/**********************************
 * @Author: Ronnie Zhang
 * @LastEditor: Ronnie Zhang
 * @LastEditTime: 2023/12/07 20:28:27
 * @Email: zclzone@outlook.com
 * Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
 **********************************/

import { ApiProperty, ApiBody } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import {
  Allow,
  IsArray,
  IsBoolean,
  IsNotEmpty,
  IsOptional,
  IsString,
  Length,
} from 'class-validator';
export class Profile {
  @ApiProperty()
  @Allow()
  nickName: string;
  @ApiProperty()
  @Allow()
  gender: number;
  @ApiProperty()
  @Allow()
  avatar: string;
  @ApiProperty()
  @Allow()
  address: string;
  @ApiProperty()
  @Allow()
  email: string;
}

export class CreateUserDto {
  @ApiProperty()
  @IsString()
  @IsNotEmpty({ message: '用户名不能为空' })
  @Length(6, 20, {
    message: `用户名长度必须大于$constraint1到$constraint2之间，当前传递的值是$value`,
  })
  username: string;

  @ApiProperty()
  @IsString()
  @IsNotEmpty({ message: '密码不能为空' })
  @Length(6, 20, { message: `密码长度必须大于$constraint1到$constraint2之间` })
  password: string;

  @ApiProperty({ required: false })
  @IsBoolean()
  @IsOptional()
  enable?: boolean;

  @ApiProperty({ required: false })
  @IsOptional()
  profile?: Profile;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsArray()
  roleIds?: number[];
}

export class UpdateUserDto {
  @ApiProperty()
  @Exclude()
  password: string;

  @ApiProperty({ required: false })
  @Exclude()
  profile?: Profile;

  @ApiProperty({ required: false })
  @IsString()
  @IsNotEmpty({ message: '用户名不能为空' })
  @Length(5, 20, {
    message: `用户名长度必须大于$constraint1到$constraint2之间，当前传递的值是$value`,
  })
  @IsOptional()
  username?: string;

  @ApiProperty({ required: false })
  @IsBoolean()
  @IsOptional()
  enable?: boolean;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsArray()
  roleIds?: number[];
}

export class UpdateProfileDto extends Profile {}

export class GetUserDto {
  @ApiProperty({ required: false })
  @Allow()
  pageSize?: number;

  @ApiProperty({ required: false })
  @Allow()
  pageNo?: number;

  @ApiProperty({ required: false })
  @Allow()
  username?: string;

  @ApiProperty({ required: false })
  @Allow()
  gender?: number;

  @ApiProperty({ required: false })
  @Allow()
  role?: number;

  @ApiProperty({ required: false })
  @Allow()
  enable?: boolean;
}

export class AddUserRolesDto {
  @ApiProperty()
  @IsArray()
  roleIds: number[];
}
export class UpdatePasswordDto {
  @ApiProperty()
  @IsString()
  @IsNotEmpty({ message: '密码不能为空' })
  @Length(6, 20, { message: `密码长度必须大于$constraint1到$constraint2之间` })
  password: string;
}
