import {
  ArrayMaxSize,
  ArrayUnique,
  IsArray,
  IsIn,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  Matches,
  MaxLength,
  Min,
} from 'class-validator';

import { CUSTOMER_TRUCK_TYPES } from './customer-truck-assignment.dto';

/**
 * Add one external customer truck to a booking.
 *  - EXPORT: the truck delivers 1–2 known containers (required, validated in the
 *    service against the booking's containers).
 *  - IMPORT: the customer does not pre-specify — containers are registered and
 *    weighed when the truck leaves, so `containerNumbers` may be omitted/empty.
 */
export class AddCustomerTruckDto {
  @IsString()
  @IsNotEmpty()
  @MaxLength(32)
  truckPlateNumber!: string;

  @IsString()
  @IsNotEmpty()
  @MaxLength(120)
  driverName!: string;

  @IsString()
  @IsNotEmpty()
  @IsIn(CUSTOMER_TRUCK_TYPES)
  truckType!: string;

  @IsOptional()
  @IsArray()
  @ArrayMaxSize(2)
  @ArrayUnique()
  @Matches(/^[A-Z]{4}\d{7}$/, {
    each: true,
    message: 'each container number must match ISO container format, e.g. ABCD1234567',
  })
  containerNumbers?: string[];

  /** Bulk: planned tonnage this truck hauls — draws down the booking total at assignment. */
  @IsOptional()
  @IsNumber()
  @Min(0)
  plannedTons?: number;

  /** Bulk: optional item/piece count on this truck. */
  @IsOptional()
  @IsNumber()
  @Min(0)
  plannedQuantity?: number;
}
