import { CsvRate } from '../../entities/csv-rate.entity';
import { PortCode } from '../../value-objects/port-code.vo';
import { Volume } from '../../value-objects/volume.vo';

/**
 * Advanced Rate Search Filters
 *
 * Filters for narrowing down rate search results
 */
export interface RateSearchFilters {
  // Company filters
  companies?: string[]; // List of company names to include

  // Volume/Weight filters
  minVolumeCBM?: number;
  maxVolumeCBM?: number;
  minWeightKG?: number;
  maxWeightKG?: number;
  palletCount?: number; // Exact pallet count (0 = any)

  // Price filters
  minPrice?: number;
  maxPrice?: number;
  currency?: 'USD' | 'EUR'; // Preferred currency for filtering

  // Transit filters
  minTransitDays?: number;
  maxTransitDays?: number;

  // Container type filters
  containerTypes?: string[]; // e.g., ['LCL', '20DRY', '40HC']

  // Surcharge filters
  onlyAllInPrices?: boolean; // Only show rates without separate surcharges

  // Date filters
  departureDate?: Date; // Filter by validity for specific date
}

/**
 * CSV Rate Search Input
 *
 * Parameters for searching rates in CSV system
 */
export interface CsvRateSearchInput {
  origin: string; // Port code (UN/LOCODE)
  destination: string; // Port code (UN/LOCODE)
  volumeCBM: number; // Volume in cubic meters
  weightKG: number; // Weight in kilograms
  palletCount?: number; // Number of pallets (0 if none)
  containerType?: string; // Optional container type filter
  filters?: RateSearchFilters; // Advanced filters

  // Service requirements for price calculation
  hasDangerousGoods?: boolean;
  requiresSpecialHandling?: boolean;
  requiresTailgate?: boolean;
  requiresStraps?: boolean;
  requiresThermalCover?: boolean;
  hasRegulatedProducts?: boolean;
  requiresAppointment?: boolean;
}

/**
 * Surcharge Item - Individual fee or charge
 */
export interface SurchargeItem {
  code: string;
  description: string;
  amount: number;
  type: 'FIXED' | 'PER_UNIT' | 'PERCENTAGE';
}

/**
 * Price Breakdown - Detailed pricing calculation
 */
export interface PriceBreakdown {
  basePrice: number;
  volumeCharge: number;
  weightCharge: number;
  palletCharge: number;
  surcharges: SurchargeItem[];
  totalSurcharges: number;
  totalPrice: number;
  currency: string;
}

/**
 * CSV Rate Search Result
 *
 * Single rate result with calculated price
 */
export interface CsvRateSearchResult {
  rate: CsvRate;
  calculatedPrice: {
    usd: number;
    eur: number;
    primaryCurrency: string;
  };
  priceBreakdown: PriceBreakdown; // Detailed price calculation
  source: 'CSV';
  matchScore: number; // 0-100, how well it matches filters
}

/**
 * CSV Rate Search Output
 *
 * Results from CSV rate search
 */
export interface CsvRateSearchOutput {
  results: CsvRateSearchResult[];
  totalResults: number;
  searchedFiles: string[]; // CSV files searched
  searchedAt: Date;
  appliedFilters: RateSearchFilters;
}

/**
 * Search CSV Rates Port (Input Port)
 *
 * Use case for searching rates in CSV-based system
 * Supports advanced filters for precise rate matching
 */
export interface SearchCsvRatesPort {
  /**
   * Execute CSV rate search with filters
   * @param input - Search parameters and filters
   * @returns Matching rates with calculated prices
   */
  execute(input: CsvRateSearchInput): Promise<CsvRateSearchOutput>;

  /**
   * Get available companies in CSV system
   * @returns List of company names that have CSV rates
   */
  getAvailableCompanies(): Promise<string[]>;

  /**
   * Get available container types in CSV system
   * @returns List of container types available
   */
  getAvailableContainerTypes(): Promise<string[]>;
}
