import { ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsArray,
  IsBoolean,
  IsOptional,
  IsString,
  ValidateNested,
} from 'class-validator';
import { DateRangeDto } from 'src/utils/datetime/dateRangeDto';
import { PaginationDto } from 'src/config/pagination/paginationDto';

/**
 * DTO used for searching and filtering sub-agent commission records.
 * Supports advanced filters, date ranges, pagination, and CSV export.
 *
 * Extends PaginationDto to include standard pagination parameters.
 */
export class SearchSubAgentCommissionDto extends PaginationDto {
  /** Global search keyword to match across relevant fields */
  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  search_title?: string;

  /** Filter by visa service country IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  visa_service_country_id?: number[];

  /** Filter by institute IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  institute_id?: number[];

  /** Filter by client originating country IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  client_from_country_id?: number[];

  /** Filter by intake IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  intake_id?: number[];

  /** Filter by commission instance IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  commission_instance?: number[];

  /** Filter by associate (sub-agent) IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  associate_id?: string[];

  /** Filter by payment mode IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  payment_mode_id?: string[];

  /** Filter by source bank account IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  from_bank_account_id?: number[];

  /** Filter by destination bank account IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  to_bank_account_id?: number[];

  /** Filter by created by user IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  created_by?: string[];

  /** Filter by updated by user IDs */
  @ApiPropertyOptional()
  @IsOptional()
  @IsArray()
  updated_by?: string[];

  /**
   * CSV export flag.
   * When true:
   * - Full dataset is returned
   * - Pagination is typically ignored
   */
  @ApiPropertyOptional()
  @IsOptional()
  @IsBoolean()
  is_csv?: boolean = false;

  /** Filter by creation date range */
  @ApiPropertyOptional({ type: DateRangeDto })
  @IsOptional()
  @ValidateNested()
  @Type(() => DateRangeDto)
  created_on?: DateRangeDto;

  /** Filter by last updated date range */
  @ApiPropertyOptional({ type: DateRangeDto })
  @IsOptional()
  @ValidateNested()
  @Type(() => DateRangeDto)
  updated_on?: DateRangeDto;
}
