import { ApiProperty } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import { IsOptional } from "class-validator";
import { Op } from "sequelize";
import { toBoolean } from "src/common/cast";
import { QueryDto } from "src/common/dto/query.dto";

export class UserQueryDto extends QueryDto {
  @ApiProperty({ required: false })
  @IsOptional()
  @Transform(({ value }) => ({ [Op.iLike]: `%${value}%` }))
  email?: string;

  @ApiProperty({ required: false })
  @Transform(({ value }) => toBoolean(value))
  @IsOptional()
  active?: boolean;

  @ApiProperty({ required: false })
  @IsOptional()
  roleId?: number;
}
