import {
  IsOptional,
  IsString,
  IsUUID,
  IsNumber,
  MaxLength,
  Min,
  Max,
  IsInt,
} from 'class-validator';

/**
 * Shared shape for a single supplier assignment on a booking item.
 * Used inside the `suppliers[]` array on the assign / patch DTOs
 * (Phase 3 of the multi-supplier refactor — see migration 1784000).
 *
 * At least one of supplier_id / supplier_name_text must be present —
 * enforced at the DB layer via the `chk_*_supplier_present` CHECK
 * constraints, not here, so a single validator can catch it later
 * without depending on cross-field logic.
 */
export class ItemSupplierInputDto {
  /** Junction row id — when present, the BE updates this assignment
   *  in place so cash-collection FKs stay on the same supplier slot. */
  @IsUUID()
  @IsOptional()
  id?: string | null;

  @IsUUID()
  @IsOptional()
  supplier_id?: string | null;

  @IsString()
  @IsOptional()
  @MaxLength(255)
  supplier_name_text?: string | null;

  @IsString()
  @IsOptional()
  @MaxLength(50)
  supplier_phone_text?: string | null;

  /** Short label — 'primary' by default, 'secondary' for the
   *  historical supplier_2 slot, or any future controlled label
   *  ('driver', 'guide', 'car'). Not an enum — vocabulary evolves. */
  @IsString()
  @IsOptional()
  @MaxLength(30)
  role?: string;

  @IsInt()
  @IsOptional()
  @Min(0)
  @Max(100)
  sort_order?: number;

  @IsNumber()
  @IsOptional()
  @Min(0)
  actual_supplier_cost?: number | null;

  @IsUUID()
  @IsOptional()
  driver_id?: string | null;

  @IsString()
  @IsOptional()
  @MaxLength(255)
  driver_name_text?: string | null;

  @IsString()
  @IsOptional()
  @MaxLength(50)
  driver_phone_text?: string | null;
}
