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

import { PartialType } from '@nestjs/mapped-types';
import { Exclude } from 'class-transformer';
import { IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator';
import { MethodType, PermissionType } from '@/types';
import { ApiProperty } from '@nestjs/swagger';

export class CreatePermissionDto {
  @ApiProperty()
  @IsString()
  name: string;

  @ApiProperty()
  @IsString()
  code: string;

  @ApiProperty()
  @IsString()
  type: PermissionType;

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

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

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

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

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

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

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

  @ApiProperty({ required: false })
  @IsString()
  @IsOptional()
  method?: MethodType;

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

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

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

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

export class UpdatePermissionDto extends PartialType(CreatePermissionDto) {
  @ApiProperty()
  @Exclude()
  type: PermissionType;
}
