import { IsIn, IsOptional, IsString, IsUUID, MaxLength } from 'class-validator';
import { PaginationDto } from '../../../common/dto/pagination.dto';

/**
 * Shared query DTO for Supplier Collection analytical endpoints.
 *
 *   search     — collector or supplier name (by-supplier); driver name (by-driver)
 *   date_from  — Date of Collection >=
 *   date_to    — Date of Collection <=
 */
export class SupplierCollectionQueryDto extends PaginationDto {
  @IsIn(['CASH', 'EXPENSE'])
  @IsOptional()
  collection_kind?: 'CASH' | 'EXPENSE';

  @IsString()
  @IsOptional()
  @MaxLength(20)
  date_from?: string;

  @IsString()
  @IsOptional()
  @MaxLength(20)
  date_to?: string;
}

/**
 * Driver breakdown for one supplier on the Supplier Collection page —
 * scoped by supplier_id OR supplier_name (for free-text suppliers).
 */
export class SupplierCollectionDriversQueryDto extends PaginationDto {
  @IsIn(['CASH', 'EXPENSE'])
  @IsOptional()
  collection_kind?: 'CASH' | 'EXPENSE';

  @IsIn(['OWN', 'SUPPLIER'])
  @IsOptional()
  collected_by_type?: 'OWN' | 'SUPPLIER';

  @IsString()
  @IsOptional()
  @MaxLength(255)
  collector_name?: string;

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

  @IsString()
  @IsOptional()
  @MaxLength(200)
  supplier_name?: string;

  @IsString()
  @IsOptional()
  @MaxLength(20)
  date_from?: string;

  @IsString()
  @IsOptional()
  @MaxLength(20)
  date_to?: string;
}
