import { RateQuote } from '@domain/entities/rate-quote.entity'; import { RateQuoteDto, PortDto, SurchargeDto, PricingDto, RouteSegmentDto, } from '../dto/rate-search-response.dto'; export class RateQuoteMapper { /** * Map domain RateQuote entity to DTO */ static toDto(entity: RateQuote): RateQuoteDto { return { id: entity.id, carrierId: entity.carrierId, carrierName: entity.carrierName, carrierCode: entity.carrierCode, origin: { code: entity.origin.code, name: entity.origin.name, country: entity.origin.country, }, destination: { code: entity.destination.code, name: entity.destination.name, country: entity.destination.country, }, pricing: { baseFreight: entity.pricing.baseFreight, surcharges: entity.pricing.surcharges.map(s => ({ type: s.type, description: s.description, amount: s.amount, currency: s.currency, })), totalAmount: entity.pricing.totalAmount, currency: entity.pricing.currency, }, containerType: entity.containerType, mode: entity.mode, etd: entity.etd.toISOString(), eta: entity.eta.toISOString(), transitDays: entity.transitDays, route: entity.route.map(segment => ({ portCode: segment.portCode, portName: segment.portName, arrival: segment.arrival?.toISOString(), departure: segment.departure?.toISOString(), vesselName: segment.vesselName, voyageNumber: segment.voyageNumber, })), availability: entity.availability, frequency: entity.frequency, vesselType: entity.vesselType, co2EmissionsKg: entity.co2EmissionsKg, validUntil: entity.validUntil.toISOString(), createdAt: entity.createdAt.toISOString(), }; } /** * Map array of RateQuote entities to DTOs */ static toDtoArray(entities: RateQuote[]): RateQuoteDto[] { return entities.map(entity => this.toDto(entity)); } }