import { IsString, IsOptional, IsNotEmpty, IsEmail } from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import { toBoolean, toNumber } from "src/common/cast";

export class UpdateUserDto {
  @ApiProperty({ example: "admin" })
  @IsOptional()
  @IsNotEmpty()
  @IsString()
  name?: string;

  @ApiProperty({ example: "admin@example.com" })
  @IsOptional()
  @IsNotEmpty()
  @IsString()
  @IsEmail()
  email?: string;

  @ApiProperty({
    example: true,
    description: "Set true if you want to activate this user",
  })
  @IsOptional()
  @Transform(({ value }) => toBoolean(value))
  active?: boolean;

  @ApiProperty({ example: 1 })
  @IsOptional()
  @Transform(({ value }) => toNumber(value))
  roleId?: number;
}
