import { CsvRate } from '../../entities/csv-rate.entity';
import { ServiceLevel } from '../../services/rate-offer-generator.service';
import { PriceBreakdown } from '../../services/csv-rate-price-calculator.service';

export { PriceBreakdown };

/**
 * Filters for narrowing CSV rate search results.
 * Volume/weight range filters removed — new schema has no per-rate volume limits.
 */
export interface RateSearchFilters {
  companies?: string[];

  // Price filter (applied to totalPriceForSorting)
  minPrice?: number;
  maxPrice?: number;
  currency?: 'USD' | 'EUR';

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

  // Route filter
  onlyDirect?: boolean; // Only show "Direct" routing

  // Container type filter
  containerTypes?: string[];

  // Date filter
  departureDate?: Date;

  // Service level filter (for offers endpoint)
  serviceLevels?: ServiceLevel[];

  // DG filter
  excludeNonDgRoutes?: boolean; // Only show DG-accepted routes
}

export interface CsvRateSearchInput {
  origin: string; // UN/LOCODE
  destination: string; // UN/LOCODE
  volumeCBM: number;
  weightKG: number;
  containerType?: string;
  hasDangerousGoods?: boolean;
  filters?: RateSearchFilters;
}

export interface CsvRateSearchResult {
  rate: CsvRate;
  priceBreakdown: PriceBreakdown;
  source: 'CSV';
  matchScore: number;
  serviceLevel?: ServiceLevel;
  priceMultiplier?: number;
  originalTransitDays?: number;
  adjustedTransitDays?: number;
}

export interface CsvRateSearchOutput {
  results: CsvRateSearchResult[];
  totalResults: number;
  searchedFiles: string[];
  searchedAt: Date;
  appliedFilters: RateSearchFilters;
}

export interface SearchCsvRatesPort {
  execute(input: CsvRateSearchInput): Promise<CsvRateSearchOutput>;
  executeWithOffers(input: CsvRateSearchInput): Promise<CsvRateSearchOutput>;
  getAvailableCompanies(): Promise<string[]>;
  getAvailableContainerTypes(): Promise<string[]>;
}
