import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, IsNumber, IsOptional, IsBoolean, Min, Max } from 'class-validator';

/**
 * Port search request DTO
 */
export class PortSearchRequestDto {
  @ApiProperty({
    example: 'Rotterdam',
    description: 'Search query - can be port name, city, or UN/LOCODE code',
  })
  @IsString()
  query: string;

  @ApiPropertyOptional({
    example: 10,
    description: 'Maximum number of results to return (default: 10)',
    minimum: 1,
    maximum: 50,
  })
  @IsNumber()
  @IsOptional()
  @Min(1)
  @Max(50)
  limit?: number;

  @ApiPropertyOptional({
    example: 'NL',
    description: 'Filter by ISO 3166-1 alpha-2 country code (e.g., NL, FR, US)',
  })
  @IsString()
  @IsOptional()
  countryFilter?: string;
}

/**
 * Port coordinates DTO
 */
export class PortCoordinatesDto {
  @ApiProperty({
    example: 51.9244,
    description: 'Latitude',
  })
  @IsNumber()
  latitude: number;

  @ApiProperty({
    example: 4.4777,
    description: 'Longitude',
  })
  @IsNumber()
  longitude: number;
}

/**
 * Port response DTO
 */
export class PortResponseDto {
  @ApiProperty({
    example: 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
    description: 'Port unique identifier',
  })
  @IsString()
  id: string;

  @ApiProperty({
    example: 'NLRTM',
    description: 'UN/LOCODE port code',
  })
  @IsString()
  code: string;

  @ApiProperty({
    example: 'Port of Rotterdam',
    description: 'Port name',
  })
  @IsString()
  name: string;

  @ApiProperty({
    example: 'Rotterdam',
    description: 'City name',
  })
  @IsString()
  city: string;

  @ApiProperty({
    example: 'NL',
    description: 'ISO 3166-1 alpha-2 country code',
  })
  @IsString()
  country: string;

  @ApiProperty({
    example: 'Netherlands',
    description: 'Full country name',
  })
  @IsString()
  countryName: string;

  @ApiProperty({
    description: 'Port coordinates (latitude/longitude)',
    type: PortCoordinatesDto,
  })
  coordinates: PortCoordinatesDto;

  @ApiPropertyOptional({
    example: 'Europe/Amsterdam',
    description: 'IANA timezone identifier',
  })
  @IsString()
  @IsOptional()
  timezone?: string;

  @ApiProperty({
    example: true,
    description: 'Whether the port is active',
  })
  @IsBoolean()
  isActive: boolean;

  @ApiProperty({
    example: 'Port of Rotterdam, Netherlands (NLRTM)',
    description: 'Full display name with code',
  })
  @IsString()
  displayName: string;
}

/**
 * Port search response DTO
 */
export class PortSearchResponseDto {
  @ApiProperty({
    description: 'List of matching ports',
    type: [PortResponseDto],
  })
  ports: PortResponseDto[];

  @ApiProperty({
    example: 10,
    description: 'Number of ports returned',
  })
  @IsNumber()
  totalMatches: number;
}
