import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  ArrayMinSize,
  IsArray,
  IsEnum,
  IsOptional,
  IsUUID,
  ValidateNested,
} from 'class-validator';

import { RouteStatus } from '../entities/route.entity';

/**
 * Segment distances are no longer part of the payload — they are resolved
 * from the configured yard_distances table (Configuration → Yard Distances)
 * and snapshotted onto route_milestones at create/update.
 */
export class CreateRouteMilestoneDto {
  @ApiProperty({ format: 'uuid' })
  @IsUUID()
  yardId!: string;
}

export class CreateRouteDto {
  @ApiProperty({ type: [CreateRouteMilestoneDto] })
  @IsArray()
  @ArrayMinSize(2)
  @ValidateNested({ each: true })
  @Type(() => CreateRouteMilestoneDto)
  milestones!: CreateRouteMilestoneDto[];

  @ApiPropertyOptional({ enum: ['AVAILABLE', 'MAINTENANCE', 'DAMAGED', 'STOP_WORKING'] })
  @IsOptional()
  @IsEnum(['AVAILABLE', 'MAINTENANCE', 'DAMAGED', 'STOP_WORKING'])
  status?: RouteStatus;
}
