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

import { ApiProperty } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import { Allow, IsArray, IsBoolean, IsNotEmpty, IsNumber, IsOptional } from 'class-validator';

export class CreateRoleDto {
  // @ApiProperty({ required: false })
  @ApiProperty()
  @IsNotEmpty({ message: '角色编码不能为空' })
  code: string;

  @ApiProperty()
  @IsNotEmpty({ message: '角色名不能为空' })
  name: string;

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

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

export class GetRolesDto {
  @ApiProperty({ required: false })
  @IsOptional()
  enable?: boolean;
}

export class UpdateRoleDto {
  @ApiProperty()
  @Exclude()
  code: string;

  @ApiProperty({ required: false })
  @IsOptional()
  name?: string;

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

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

export class AddRolePermissionsDto {
  @ApiProperty()
  @IsNumber()
  id: number;

  @ApiProperty()
  @IsArray()
  permissionIds: number[];
}

export class AddRoleUsersDto {
  @ApiProperty()
  @IsArray()
  userIds: number[];
}

export class AddRoleButtonsDto {
  @ApiProperty()
  @IsNumber()
  id: number;

  @ApiProperty()
  @IsNumber()
  menuId: number;

  @ApiProperty()
  @IsArray()
  buttons: string[];
}

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

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

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

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