export type ServiceLevel = 'RAPID' | 'STANDARD' | 'ECONOMIC';
export type DgSurchargeStatus = 'computed' | 'on_request' | 'not_accepted';

export interface FobBreakdown {
  documentation: number;
  isps: number;
  handling: number;
  solas: number;
  customs: number;
  ams_aci: number;
  isf5: number;
  dgAdmin: number;
}

export interface PriceBreakdown {
  // Freight (in freightCurrency)
  freightCharge: number;
  freightCurrency: string;

  // FOB (in fobCurrency)
  fobFixed: number;
  fobHandling: number;
  fobDG: number;
  fobCurrency: string;
  fobBreakdown: FobBreakdown;

  // DG surcharge
  dgSurchargeAmount: number | null;
  dgSurchargeCurrency: string;
  dgSurchargeStatus: DgSurchargeStatus;

  // Totals
  totalFreight: number;
  totalFob: number;
  totalPriceForSorting: number; // naive sum for sorting
  primaryCurrency: string;
}

export interface CsvRateSearchRequest {
  origin: string;
  destination: string;
  volumeCBM: number;
  weightKG: number;
  containerType?: string;
  hasDangerousGoods?: boolean;
  filters?: RateSearchFilters;
}

export interface RateSearchFilters {
  companies?: string[];
  onlyDirect?: boolean;
  excludeNonDgRoutes?: boolean;
  minPrice?: number;
  maxPrice?: number;
  currency?: 'USD' | 'EUR';
  minTransitDays?: number;
  maxTransitDays?: number;
  containerTypes?: string[];
  departureDate?: string;
  serviceLevels?: ServiceLevel[];
}

export interface CsvRateSearchResult {
  companyName: string;
  companyEmail: string;
  originCFS: string;
  origin: string;
  portOfLoading: string;
  routing: string;
  destinationCFS: string;
  destination: string;
  destinationCountry: string;
  containerType: string;
  priceBreakdown: PriceBreakdown;
  frequency: string;
  transitDays: number;
  validUntil: string;
  dgAccepted: boolean;
  dgSurchargeStatus: DgSurchargeStatus;
  remarks: string;
  source: string;
  matchScore: number;
  serviceLevel?: ServiceLevel;
  priceMultiplier?: number;
  originalTransitDays?: number;
  adjustedTransitDays?: number;
}

export interface CsvRateSearchResponse {
  results: CsvRateSearchResult[];
  totalResults: number;
  searchedFiles: string[];
  searchedAt: string;
  appliedFilters: Record<string, any>;
}
