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

export class CreateSupplierCostPriceDto {
  @IsUUID()
  supplier_id: string;

  @IsUUID()
  transport_service_id: string;

  /**
   * Vehicle type — required for PVT, omitted/NULL for SIC. The
   * service layer normalises: SIC always forces vehicle_type_id=null
   * on save even if the client passes one in, matching the schema's
   * partial-unique-index assumption.
   */
  @IsUUID()
  @IsOptional()
  vehicle_type_id?: string | null;

  /**
   * Sale mode — defaults to PVT when omitted to preserve the
   * pre-mode contract for callers that haven't been updated.
   */
  @IsIn(['PVT', 'SIC'])
  @IsOptional()
  mode?: 'PVT' | 'SIC';

  /** Optional — null means "all-season / default" tier. */
  @IsUUID()
  @IsOptional()
  season_id?: string | null;

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

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

  @IsString()
  @IsOptional()
  notes?: string | null;

  @IsBoolean()
  @IsOptional()
  is_active?: boolean;
}

/**
 * Bulk-apply payload for the "set one price across…" shortcuts the
 * stakeholder asked for. Applies a single cost price to every
 * combination of the scoped ids — e.g. one supplier, all services,
 * one vehicle type. Missing rows are created; existing rows are
 * updated.
 */
export class BulkApplySupplierCostPriceDto {
  @IsUUID()
  supplier_id: string;

  /** Omit to apply across every transport service in scope. */
  @IsUUID(undefined, { each: true })
  @IsOptional()
  transport_service_ids?: string[];

  /** Omit to apply across every vehicle type.
   *  Ignored when mode === 'SIC' — SIC has no vehicle axis. */
  @IsUUID(undefined, { each: true })
  @IsOptional()
  vehicle_type_ids?: string[];

  /** Sale mode for the bulk-apply scope. Defaults to PVT. */
  @IsIn(['PVT', 'SIC'])
  @IsOptional()
  mode?: 'PVT' | 'SIC';

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

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

  @IsUUID()
  @IsOptional()
  currency_id?: string | null;
}
