import { IsString, IsArray, ValidateNested } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';

export class PassengerSeatDto {
  @ApiProperty({ example: 'passenger-uuid', description: 'Passenger UUID' })
  @IsString() passengerId: string;

  @ApiProperty({ example: 'seat-uuid', description: 'Seat UUID assigned to this passenger' })
  @IsString() seatId: string;
}

export class HoldSeatsDto {
  @ApiProperty({ example: 'schedule-uuid', description: 'TrainSchedule UUID' })
  @IsString() scheduleId: string;

  @ApiProperty({ example: 'station-uuid', description: 'Origin station UUID — scopes the hold to a leg so the seat can be reused on non-overlapping legs' })
  @IsString() originStationId: string;

  @ApiProperty({ example: 'station-uuid', description: 'Destination station UUID for this leg' })
  @IsString() destinationStationId: string;

  @ApiProperty({
    type: [PassengerSeatDto],
    description: 'One entry per passenger. Each passenger is assigned exactly one seat. Duplicate passengerId or seatId within the same request is rejected.',
    example: [
      { passengerId: 'passenger-uuid-1', seatId: 'seat-uuid-1' },
      { passengerId: 'passenger-uuid-2', seatId: 'seat-uuid-2' },
    ],
  })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => PassengerSeatDto)
  passengers: PassengerSeatDto[];
}
