import {
  IsDefined,
  IsString,
  IsBoolean,
  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 CreateUserDto {
  @ApiProperty({ example: "083333333333" })
  @IsDefined()
  @IsNotEmpty()
  @IsString()
  phoneNumber: string;

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

  @ApiProperty({ example: "password" })
  @IsString()
  @IsOptional()
  password: string;

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

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