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

/**
 * Inline supplier-cost edit from Movement Chart on an existing
 * transport row. Internal margin only — never produces a settlement
 * row and never touches the customer-facing total / invoice.
 */
export class UpdateActualSupplierCostDto {
  // Nullable on the wire (string 'null' on input is reduced to null in
  // the service) so ops can clear an override and fall back to the
  // master rate. `null` here means "remove override".
  @IsNumber()
  @IsOptional()
  @Min(0)
  actual_supplier_cost?: number | null;
}

/**
 * "+ Add amended transport" on Movement Chart. Creates a new
 * booking_transport_items row with `is_amended = true` and raises
 * exactly one COLLECTION settlement against the customer's outstanding
 * balance (qty × unit_price), source = MOVEMENT_CHART.
 *
 * Pickup time / dropoff time / addresses are optional — ops can fill
 * later from the chart's standard inline editors.
 */
export class CreateAmendedTransportDto {
  @IsUUID()
  booking_id: string;

  @IsUUID()
  transport_service_id: string;

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

  @IsNumber()
  @Min(1)
  quantity: number;

  @IsNumber()
  @Min(0)
  unit_price: number;

  @IsString()
  date: string; // ISO date — required so the row sorts correctly

  @IsString()
  @IsOptional()
  @MaxLength(10)
  pickup_time?: string;

  @IsString()
  @IsOptional()
  @MaxLength(10)
  dropoff_time?: string;

  @IsString()
  @IsOptional()
  @MaxLength(500)
  pickup_address?: string;

  @IsString()
  @IsOptional()
  @MaxLength(500)
  dropoff_address?: string;

  @IsString()
  @IsOptional()
  notes?: string;
}
