import { Injectable } from '@nestjs/common';
import { Port } from '@domain/entities/port.entity';
import { PortResponseDto, PortSearchResponseDto } from '../dto/port.dto';

@Injectable()
export class PortMapper {
  /**
   * Map Port entity to PortResponseDto
   */
  static toDto(port: Port): PortResponseDto {
    return {
      id: port.id,
      code: port.code,
      name: port.name,
      city: port.city,
      country: port.country,
      countryName: port.countryName,
      coordinates: {
        latitude: port.coordinates.latitude,
        longitude: port.coordinates.longitude,
      },
      timezone: port.timezone,
      isActive: port.isActive,
      displayName: port.getDisplayName(),
    };
  }

  /**
   * Map array of Port entities to array of PortResponseDto
   */
  static toDtoArray(ports: Port[]): PortResponseDto[] {
    return ports.map(port => this.toDto(port));
  }

  /**
   * Map Port search output to PortSearchResponseDto
   */
  static toSearchResponseDto(ports: Port[], totalMatches: number): PortSearchResponseDto {
    return {
      ports: this.toDtoArray(ports),
      totalMatches,
    };
  }
}
