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

/**
 * "Mark this service as requiring cash-at-service collection."
 *
 * One of transport_item_id / activity_item_id / special_item_id MUST
 * be supplied — the service enforces exactly-one via the DB CHECK
 * plus a friendlier service-layer error before we hit the FK.
 *
 * `service_type` is redundant with the FK but the CHECK constraint
 * makes it non-negotiable in the row shape, so we accept it up front.
 */
export class CreateServicePaymentCollectionDto {
  @IsIn(['TRANSPORT', 'ACTIVITY', 'SPECIAL'])
  service_type: 'TRANSPORT' | 'ACTIVITY' | 'SPECIAL';

  @IsOptional()
  @IsUUID()
  transport_item_id?: string;

  @IsOptional()
  @IsUUID()
  activity_item_id?: string;

  @IsOptional()
  @IsUUID()
  special_item_id?: string;

  /** Junction row for the supplier this collection belongs to.
   *  When omitted, the service binds to the primary supplier
   *  (lowest sort_order) on the service item. */
  @IsOptional()
  @IsUUID()
  transport_item_supplier_id?: string;

  @IsOptional()
  @IsUUID()
  activity_item_supplier_id?: string;

  @IsOptional()
  @IsUUID()
  special_item_supplier_id?: string;

  @IsNumber({ maxDecimalPlaces: 2 })
  @Min(0)
  expected_amount: number;

  @IsUUID()
  currency_id: string;

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