import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  ArrayMinSize,
  IsArray,
  IsBoolean,
  IsDateString,
  IsInt,
  IsNumber,
  IsOptional,
  IsUUID,
  Min,
} from 'class-validator';

export class PreviewTrainScheduleDto {
  @ApiProperty({ type: [String] })
  @IsArray()
  @ArrayMinSize(1)
  @IsUUID('4', { each: true })
  bookingIds!: string[];

  @ApiProperty({ example: '2026-06-20T08:00:00.000Z' })
  @IsDateString()
  scheduleDate!: string;

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

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

  @ApiPropertyOptional({
    format: 'uuid',
    description: 'Allow bookings already assigned to this schedule (re-assign / reschedule)',
  })
  @IsOptional()
  @IsUUID()
  targetScheduleId?: string;

  @ApiPropertyOptional({ description: 'Maximum total booking weight allowed on this train' })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  maxTrainWeightTons?: number;

  @ApiPropertyOptional({ description: 'Maximum total wagon length allowed on this train' })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  @Min(1)
  maxTrainLengthMeters?: number;

  @ApiPropertyOptional({ description: 'Maximum wagons allowed on this train' })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  maxWagonsPerTrain?: number;

  @ApiPropertyOptional({
    description:
      'Reverse the wagon order on the train: the physically-last wagon becomes ' +
      'position 1. The composition and allocations are unchanged — only the order ' +
      'flips, applied at build so the stored train and schedule stay in sync.',
    default: false,
  })
  @IsOptional()
  @IsBoolean()
  reverseWagonOrder?: boolean;
}
