import { IsString, IsNotEmpty, IsIn, IsArray, ArrayMaxSize, ArrayUnique, Matches, IsOptional } from 'class-validator';
import { CUSTOMER_TRUCK_TYPES } from './customer-truck-assignment.dto';

export class BulkCustomerTruckRow {
  @IsString()
  @IsNotEmpty()
  truckPlateNumber!: string;

  @IsString()
  @IsNotEmpty()
  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 must be ISO format (e.g. ABCD1234567)',
  })
  containerNumbers?: (string | null)[];
}

export class BulkCustomerTrucksDto {
  @IsArray()
  @ArrayMaxSize(100)
  trucks!: BulkCustomerTruckRow[];
}

export interface BulkTruckUploadResult {
  success: number;
  failed: number;
  errors: Array<{
    row: number;
    truck: string;
    reason: string;
  }>;
  created: Array<{
    truckPlateNumber: string;
    driverName: string;
    containers: number;
  }>;
}
