import {
  ArrayMaxSize,
  ArrayUnique,
  IsArray,
  IsDateString,
  IsNumber,
  IsOptional,
  Matches,
  Min,
} from 'class-validator';

/**
 * Register an import self-haul truck leaving the port: the containers it actually
 * loaded (staff read them off the truck) and the weighed gross. Container numbers
 * are optional here only because they may already have been recorded; the weighed
 * gross is required.
 */
export class DepartCustomerTruckDto {
  @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[];

  @IsNumber()
  @Min(0)
  grossWeightKg!: number;

  /** Gate-out time. Defaults to now when omitted. */
  @IsOptional()
  @IsDateString()
  gateOutTime?: string;
}
