/**
 * Trader type detection
 * Maps trader names to template types (case-insensitive)
 */

export type TraderType = 'ketron' | 'larainvest' | 'other';

/**
 * Detects trader type from trader name (case-insensitive)
 * @param traderName - Name of the trader (e.g., "KETRON GLOBAL PTE. LTD")
 * @returns TraderType ('ketron', 'larainvest', or 'other')
 */
export function getTraderType(traderName: string | undefined): TraderType {
  if (!traderName) return 'other';
  
  const normalized = traderName.toLowerCase();
  
  if (normalized.includes('ketron')) {
    return 'ketron';
  }
  
  if (normalized.includes('larainvest')) {
    return 'larainvest';
  }
  
  return 'other';
}

/**
 * Gets the template file name for a given trader type and document type
 */
export function getTemplateFileName(traderType: TraderType, documentType: 'proforma' | 'invoice'): string {
  const templateMap: Record<TraderType, Record<string, string>> = {
    ketron: {
      proforma: 'ProformaKetron.ods',
      invoice: 'InvoiceKetron.ods',
    },
    larainvest: {
      proforma: 'ProformaLarainvest.ods',
      invoice: 'InvoiceLarainvest.ods',
    },
    other: {
      proforma: 'ProformaLarainvest.ods',
      invoice: 'InvoiceLarainvest.ods',
    },
  };
  
  return templateMap[traderType][documentType];
}
