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 records based on association type.
 * Ensures the provided type is a valid numeric enum value
 * from AssociationType.
 */
export class FetchByAssociationTypesDto {
  /**
   * Association type identifier.
   * Must be a valid numeric value from the AssociationType enum.
   * Example: INSTITUTE, AGENT, PARTNER, etc.
   */
  @ApiProperty({
    enum: AssociationType,
    example: AssociationType.INSTITUTE,
  })
  @IsNotEmpty() // Field must be provided
  @Type(() => Number) // Transform incoming value to number
  @IsInt() // Ensure value is an integer
  @IsIn(Object.values(AssociationType).filter((v) => typeof v === 'number')) // Allow only numeric enum values
  type: AssociationType;
}
