// Incoterms 2020 Integration

export enum Incoterm {
  FOB = 'FOB', // Free On Board
  CIF = 'CIF', // Cost, Insurance and Freight
  EXW = 'EXW', // Ex Works
  FCA = 'FCA', // Free Carrier
  CPT = 'CPT', // Carriage Paid To
  CIP = 'CIP', // Carriage and Insurance Paid To
  DAP = 'DAP', // Delivered At Place
  DPU = 'DPU', // Delivered At Place Unloaded
  DDP = 'DDP', // Delivered Duty Paid
}

export interface IncotermsData {
  incoterm: Incoterm;
  riskTransferPoint: string;
  freightResponsibility: string;
  insuranceResponsibility: string;
}

export class IncotermsService {
  /**
   * Get Incoterms data
   */
  getIncotermsData(incoterm: Incoterm): IncotermsData {
    const data: Record<Incoterm, IncotermsData> = {
      [Incoterm.FOB]: {
        incoterm: Incoterm.FOB,
        riskTransferPoint: 'On board vessel at port of shipment',
        freightResponsibility: 'Buyer',
        insuranceResponsibility: 'Buyer',
      },
      [Incoterm.CIF]: {
        incoterm: Incoterm.CIF,
        riskTransferPoint: 'On board vessel at port of shipment',
        freightResponsibility: 'Seller',
        insuranceResponsibility: 'Seller',
      },
      // Add other Incoterms as needed
      [Incoterm.EXW]: {
        incoterm: Incoterm.EXW,
        riskTransferPoint: 'At seller\'s premises',
        freightResponsibility: 'Buyer',
        insuranceResponsibility: 'Buyer',
      },
      [Incoterm.FCA]: {
        incoterm: Incoterm.FCA,
        riskTransferPoint: 'At carrier\'s facility',
        freightResponsibility: 'Buyer',
        insuranceResponsibility: 'Buyer',
      },
      [Incoterm.CPT]: {
        incoterm: Incoterm.CPT,
        riskTransferPoint: 'At carrier\'s facility',
        freightResponsibility: 'Seller',
        insuranceResponsibility: 'Buyer',
      },
      [Incoterm.CIP]: {
        incoterm: Incoterm.CIP,
        riskTransferPoint: 'At carrier\'s facility',
        freightResponsibility: 'Seller',
        insuranceResponsibility: 'Seller',
      },
      [Incoterm.DAP]: {
        incoterm: Incoterm.DAP,
        riskTransferPoint: 'At destination',
        freightResponsibility: 'Seller',
        insuranceResponsibility: 'Buyer',
      },
      [Incoterm.DPU]: {
        incoterm: Incoterm.DPU,
        riskTransferPoint: 'At destination unloaded',
        freightResponsibility: 'Seller',
        insuranceResponsibility: 'Buyer',
      },
      [Incoterm.DDP]: {
        incoterm: Incoterm.DDP,
        riskTransferPoint: 'At destination',
        freightResponsibility: 'Seller',
        insuranceResponsibility: 'Seller',
      },
    };

    return data[incoterm];
  }
}

export const incotermsService = new IncotermsService();

