import { Supplier } from '@/types';

export interface SupplierConfig {
  key: Supplier;
  label: string;
  ediType: 'xlsx' | 'csv';
  familleColumn: string | number;
  familleFilter: string;
  columns: {
    centreCode: string | number;
    centreName: string | number;
    codeArticle: string | number;
    description: string | number;
    quantity: string | number;
    unitPrice: string | number;
    discount: string | number;
    invoiceNumber: string | number;
    invoiceDate: string | number;
    sign: string | number;
  };
  exclusions: string[];
  acronyms: Record<string, string[]>;
}

export const SUPPLIERS: Record<Supplier, SupplierConfig> = {
  signia: {
    key: 'signia',
    label: 'Signia',
    ediType: 'xlsx',
    familleColumn: 'Famille',
    familleFilter: 'PR',
    columns: {
      centreCode: 'CompteClient',
      centreName: 'NomCentre',
      codeArticle: 'CodeArticle',
      description: 'DescriptionArticle',
      quantity: 'Quantité',
      unitPrice: 'PrixUnitaireNet',
      discount: 'Remise%',
      invoiceNumber: 'NuméroFacture',
      invoiceDate: 'DateFacture',
      sign: 'Signe',
    },
    exclusions: ['ECOTAXE', 'PORT', 'REPARATION', 'GARANTIE'],
    acronyms: {
      'NX': ['Nexia'],
      'AX': ['Augmented Xperience', 'AX'],
      'IX': ['Integrated Xperience', 'IX'],
      'PX': ['Pure Experience', 'PX'],
      'C&G': ['Charge and Go', 'Charge & Go'],
      'SP': ['Super Power'],
      'UP': ['Ultra Power'],
      'INSIO': ['Insio'],
      'SILK': ['Silk'],
      'PURE': ['Pure'],
      'MOTION': ['Motion'],
      'STYLETTO': ['Styletto'],
      'CROS': ['CROS'],
      'CIC': ['CIC'],
      'ITC': ['ITC'],
      'ITE': ['ITE'],
      'IIC': ['IIC'],
      'RIC': ['RIC'],
      'MRIC': ['RIC', 'Mini RIC'],
      'BTE': ['BTE'],
      'BCT': ['BTE', 'Contour'],
    },
  },
  resound: {
    key: 'resound',
    label: 'ReSound',
    ediType: 'xlsx',
    familleColumn: 'Famille',
    familleFilter: 'CONTOUR',
    columns: {
      centreCode: 'CompteClient',
      centreName: 'NomCentre',
      codeArticle: 'CodeArticle',
      description: 'DescriptionArticle',
      quantity: 'Quantité',
      unitPrice: 'PrixUnitaireBrut',
      discount: 'Remise%',
      invoiceNumber: 'NuméroFacture',
      invoiceDate: 'DateFacture',
      sign: 'Signe',
    },
    exclusions: ['ECOTAXE', 'PORT', 'REPARATION', 'AUTRES'],
    acronyms: {
      'NX': ['Nexia'],
      'RU': ['Omnia'],
      'EQ': ['Enzo Q'],
      'LI': ['LiNX Quattro', 'LiNX'],
      'KEY': ['Key'],
      'ONE': ['One'],
      'OMNIA': ['Omnia'],
      'NEXIA': ['Nexia'],
      'RIE': ['RIC', 'RIE'],
      'MRIE': ['RIE', 'Mini RIE'],
      'MRIC': ['RIC', 'Mini RIC'],
      'BTE': ['BTE', 'Contour'],
      'ITE': ['ITE'],
      'ITC': ['ITC'],
      'CIC': ['CIC'],
      'DRWC': ['Rechargeable'],
      'DW': ['DW', 'Direct Wire'],
      'SPK': ['Speaker'],
      'HP': ['High Power'],
    },
  },
  starkey: {
    key: 'starkey',
    label: 'Starkey',
    ediType: 'csv',
    familleColumn: 6,
    familleFilter: 'PR',
    columns: {
      centreCode: 0,
      centreName: 0,
      codeArticle: 7,
      description: 8,
      quantity: 9,
      unitPrice: 13,
      discount: 10,
      invoiceNumber: 3,
      invoiceDate: 4,
      sign: 2,
    },
    exclusions: ['AC', 'CONT', 'EMB', 'FA', 'OPT', 'PO', 'PT', 'REPA', 'TEL'],
    acronyms: {
      'GENESIS': ['Genesis AI'],
      'EVOLV': ['Evolv AI'],
      'LIVIO': ['Livio AI', 'Livio Edge AI'],
      'OMEGA': ['Omega AI'],
      'PICASSO': ['Picasso'],
      'MUSE': ['Muse'],
      'MRIC': ['RIC', 'Mini RIC', 'MRIC'],
      'MRIE': ['RIE', 'Mini RIE', 'MRIE'],
      'RIC': ['RIC'],
      'BTE': ['BTE'],
      'ITC': ['ITC'],
      'CIC': ['CIC'],
      'IIC': ['IIC'],
      'ITE': ['ITE'],
      'NW': ['Non-Wireless'],
      'RT': ['Rechargeable'],
      'SHT': ['Standard'],
    },
  },
};

export const SUPPLIER_LIST: Supplier[] = ['signia', 'resound', 'starkey'];

export const MONTHS = [
  { value: '01', label: 'Janvier' },
  { value: '02', label: 'Février' },
  { value: '03', label: 'Mars' },
  { value: '04', label: 'Avril' },
  { value: '05', label: 'Mai' },
  { value: '06', label: 'Juin' },
  { value: '07', label: 'Juillet' },
  { value: '08', label: 'Août' },
  { value: '09', label: 'Septembre' },
  { value: '10', label: 'Octobre' },
  { value: '11', label: 'Novembre' },
  { value: '12', label: 'Décembre' },
];

export function getMonthLabel(monthStr: string): string {
  // monthStr = "YYYY-MM" or "MM"
  const mm = monthStr.includes('-') ? monthStr.split('-')[1] : monthStr;
  return MONTHS.find((m) => m.value === mm)?.label ?? monthStr;
}
