import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsNumber, IsUUID, Min } from 'class-validator';

const toNumber = ({ value }: { value: unknown }) =>
  value === '' || value == null ? value : Number(value);

export class CreateYardDistanceDto {
  @ApiProperty({ format: 'uuid' })
  @IsUUID()
  fromYardId!: string;

  @ApiProperty({ format: 'uuid' })
  @IsUUID()
  toYardId!: string;

  @ApiProperty({ description: 'Rail distance between the two yards in kilometres', example: 445 })
  @Transform(toNumber)
  @IsNumber()
  @Min(0.01)
  distanceKm!: number;
}
