import { IsIn, IsInt, IsNotEmpty } from 'class-validator';
import { Type } from 'class-transformer';
import { AssociationType } from 'src/utils/enums/enum';
import { ApiProperty } from '@nestjs/swagger';

/**
 * DTO used to fetch entities filtered by association type.
 *
 * Example use case:
 * - Fetch commissions, contracts, or users associated with
 *   a specific type like INSTITUTE, AGENT, or SUB_AGENT.
 */
export class FetchByAssociationTypesDto {
  /**
   * Type of association to filter by.
   *
   * Required field:
   * - Must be a number.
   * - Must be one of the valid AssociationType enum values.
   * - Example: AssociationType.INSTITUTE
   */
  @ApiProperty({
    enum: AssociationType,
    example: AssociationType.INSTITUTE,
  })
  @IsNotEmpty()
  @Type(() => Number)
  @IsInt()
  @IsIn(Object.values(AssociationType).filter((v) => typeof v === 'number'))
  type: AssociationType;
}
