import {
  ArrayMaxSize,
  ArrayUnique,
  IsArray,
  IsOptional,
  IsString,
  IsUUID,
  ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';

export class LastMileVehicleInput {
  @IsUUID()
  vehicleId!: string;

  /**
   * Containers this truck carries: one 40ft, or up to two 20ft. Omit for bulk
   * (the truck hauls loose tonnage and is weighed out on exit).
   */
  @IsOptional()
  @IsArray()
  @ArrayMaxSize(2)
  @ArrayUnique()
  @IsString({ each: true })
  containerNumbers?: string[];

  /** @deprecated Single-container form — use `containerNumbers`. Still accepted. */
  @IsOptional()
  @IsString()
  containerNumber?: string;
}

/** Replace the full set of vehicles (with their containers) on a delivery. */
export class SetVehiclesDto {
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => LastMileVehicleInput)
  vehicles!: LastMileVehicleInput[];
}
