import { ApiProperty } from "@nestjs/swagger"
import {
  IsArray,
  IsBoolean,
  IsDate,
  IsInt,
  IsNumber,
  IsOptional,
  ValidateNested,
} from "class-validator"
import { Transform, Type } from "class-transformer"

export class FleetAssignmentDto {
  @ApiProperty({
    example: 1,
    description: "ID of the stop",
  })
  @IsNumber()
  @IsOptional()
  trip_fleet_id: number

  @ApiProperty({
    example: 101,
    description: "ID of the fleet to be assigned",
  })
  @IsOptional()
  @IsInt()
  @Transform(({ value }) => (value === null ? null : value))
  fleet_id: number | null

  @ApiProperty({
    example: 1,
    description: "ID of the fleet type to be assigned",
  })
  @IsInt()
  @IsOptional()
  @Transform(({ value }) => (value === null ? null : value))
  fleet_type_id?: number

  @ApiProperty({
    example: new Date(),
    description: "Completion date of the trip (optional)",
  })
  @IsOptional()
  @IsDate()
  trip_completed_at?: Date

  @ApiProperty({
    example: 201,
    description: "ID of the driver to be assigned (optional)",
    required: false,
  })
  @IsOptional()
  @IsInt()
  @Transform(({ value }) => (value === null ? null : value))
  driver_id?: number | null

  @ApiProperty({
    example: "false",
    description: "Additional notes about the stop",
    required: false,
  })
  @IsOptional()
  @IsBoolean()
  should_remove?: boolean
}

export class AssignFleetsToTripDto {
  @ApiProperty({
    type: [FleetAssignmentDto],
    description: "Array of fleet and optional driver assignments",
  })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => FleetAssignmentDto)
  assignments: FleetAssignmentDto[]
}
