import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class PortDto {
  @ApiProperty({ example: 'NLRTM' })
  code: string;

  @ApiProperty({ example: 'Rotterdam' })
  name: string;

  @ApiProperty({ example: 'Netherlands' })
  country: string;
}

export class SurchargeDto {
  @ApiProperty({ example: 'BAF', description: 'Surcharge type code' })
  type: string;

  @ApiProperty({ example: 'Bunker Adjustment Factor' })
  description: string;

  @ApiProperty({ example: 150.0 })
  amount: number;

  @ApiProperty({ example: 'USD' })
  currency: string;
}

export class PricingDto {
  @ApiProperty({ example: 1500.0, description: 'Base ocean freight' })
  baseFreight: number;

  @ApiProperty({ type: [SurchargeDto] })
  surcharges: SurchargeDto[];

  @ApiProperty({ example: 1700.0, description: 'Total amount including all surcharges' })
  totalAmount: number;

  @ApiProperty({ example: 'USD' })
  currency: string;
}

export class RouteSegmentDto {
  @ApiProperty({ example: 'NLRTM' })
  portCode: string;

  @ApiProperty({ example: 'Port of Rotterdam' })
  portName: string;

  @ApiPropertyOptional({ example: '2025-02-15T10:00:00Z' })
  arrival?: string;

  @ApiPropertyOptional({ example: '2025-02-15T14:00:00Z' })
  departure?: string;

  @ApiPropertyOptional({ example: 'MAERSK ESSEX' })
  vesselName?: string;

  @ApiPropertyOptional({ example: '025W' })
  voyageNumber?: string;
}

export class RateQuoteDto {
  @ApiProperty({ example: '550e8400-e29b-41d4-a716-446655440000' })
  id: string;

  @ApiProperty({ example: '550e8400-e29b-41d4-a716-446655440001' })
  carrierId: string;

  @ApiProperty({ example: 'Maersk Line' })
  carrierName: string;

  @ApiProperty({ example: 'MAERSK' })
  carrierCode: string;

  @ApiProperty({ type: PortDto })
  origin: PortDto;

  @ApiProperty({ type: PortDto })
  destination: PortDto;

  @ApiProperty({ type: PricingDto })
  pricing: PricingDto;

  @ApiProperty({ example: '40HC' })
  containerType: string;

  @ApiProperty({ example: 'FCL', enum: ['FCL', 'LCL'] })
  mode: 'FCL' | 'LCL';

  @ApiProperty({ example: '2025-02-15T10:00:00Z', description: 'Estimated Time of Departure' })
  etd: string;

  @ApiProperty({ example: '2025-03-17T14:00:00Z', description: 'Estimated Time of Arrival' })
  eta: string;

  @ApiProperty({ example: 30, description: 'Transit time in days' })
  transitDays: number;

  @ApiProperty({ type: [RouteSegmentDto], description: 'Route segments with port details' })
  route: RouteSegmentDto[];

  @ApiProperty({ example: 85, description: 'Available container slots' })
  availability: number;

  @ApiProperty({ example: 'Weekly' })
  frequency: string;

  @ApiPropertyOptional({ example: 'Container Ship' })
  vesselType?: string;

  @ApiPropertyOptional({ example: 12500.5, description: 'CO2 emissions in kg' })
  co2EmissionsKg?: number;

  @ApiProperty({ example: '2025-02-15T10:15:00Z', description: 'Quote expiration timestamp' })
  validUntil: string;

  @ApiProperty({ example: '2025-02-15T10:00:00Z' })
  createdAt: string;
}

export class RateSearchResponseDto {
  @ApiProperty({ type: [RateQuoteDto] })
  quotes: RateQuoteDto[];

  @ApiProperty({ example: 5, description: 'Total number of quotes returned' })
  count: number;

  @ApiProperty({ example: 'NLRTM' })
  origin: string;

  @ApiProperty({ example: 'CNSHA' })
  destination: string;

  @ApiProperty({ example: '2025-02-15' })
  departureDate: string;

  @ApiProperty({ example: '40HC' })
  containerType: string;

  @ApiProperty({ example: 'FCL' })
  mode: string;

  @ApiProperty({ example: true, description: 'Whether results were served from cache' })
  fromCache: boolean;

  @ApiProperty({ example: 234, description: 'Query response time in milliseconds' })
  responseTimeMs: number;
}
