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

/**
 * DTO used to fetch users based on specific criteria.
 *
 * This DTO allows filtering users by the type of action they performed
 * and the type of association they belong to.
 */
export class FetchByUsersDto {
  /**
   * Type of user action to filter by.
   *
   * Required field:
   * - Must be one of the ByUserType enum values.
   * - Example: CREATED, UPDATED
   */
  @ApiProperty({ enum: ByUserType })
  @IsNotEmpty()
  @IsIn(Object.values(ByUserType))
  by: ByUserType;

  /**
   * Association type of the users.
   *
   * Required field:
   * - Must be a number corresponding to a valid AssociationType enum value.
   * - Example: AssociationType.INSTITUTE
   */
  @ApiProperty({
    enum: AssociationType,
    example: AssociationType.INSTITUTE,
  })
  @IsNotEmpty()
  @Type(() => Number)
  @IsInt()
  @IsIn(Object.values(AssociationType).filter((v) => typeof v === 'number'))
  type: AssociationType;
}
