import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNumber, IsOptional, IsArray, IsIn, MinLength, MaxLength } from 'class-validator';

export class CreateRoleDto {
  @ApiProperty({ description: '角色名称', example: '超级管理员' })
  @IsString()
  @MinLength(2)
  @MaxLength(50)
  roleName: string;

  @ApiProperty({ description: '角色描述', example: '系统超级管理员，拥有所有权限', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(200)
  roleDesc?: string;

  @ApiProperty({ description: '角色状态', example: 1, enum: [0, 1] })
  @IsNumber()
  @IsIn([0, 1])
  status: number;

  @ApiProperty({ description: '应用类型', example: 'admin', enum: ['admin', 'api'] })
  @IsString()
  @IsIn(['admin', 'api'])
  appType: string;

  @ApiProperty({ description: '权限规则', example: [], required: false })
  @IsOptional()
  @IsArray()
  rules?: number[];
}

export class UpdateRoleDto {
  @ApiProperty({ description: '角色名称', example: '超级管理员', required: false })
  @IsOptional()
  @IsString()
  @MinLength(2)
  @MaxLength(50)
  roleName?: string;

  @ApiProperty({ description: '角色描述', example: '系统超级管理员，拥有所有权限', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(200)
  roleDesc?: string;

  @ApiProperty({ description: '角色状态', example: 1, enum: [0, 1], required: false })
  @IsOptional()
  @IsNumber()
  @IsIn([0, 1])
  status?: number;

  @ApiProperty({ description: '权限规则', example: [], required: false })
  @IsOptional()
  @IsArray()
  rules?: number[];
}

export class QueryRoleDto {
  @ApiProperty({ description: '页码', example: 1, required: false })
  @IsOptional()
  @IsNumber()
  page?: number;

  @ApiProperty({ description: '每页数量', example: 20, required: false })
  @IsOptional()
  @IsNumber()
  limit?: number;

  @ApiProperty({ description: '关键词搜索', example: '管理员', required: false })
  @IsOptional()
  @IsString()
  keyword?: string;

  @ApiProperty({ description: '角色状态', example: 1, enum: [0, 1], required: false })
  @IsOptional()
  @IsNumber()
  @IsIn([0, 1])
  status?: number;

  @ApiProperty({ description: '应用类型', example: 'admin', enum: ['admin', 'api'], required: false })
  @IsOptional()
  @IsString()
  @IsIn(['admin', 'api'])
  appType?: string;
}

export class BatchUpdateStatusDto {
  @ApiProperty({ description: '角色ID列表', example: [1, 2, 3] })
  @IsArray()
  @IsNumber({}, { each: true })
  roleIds: number[];

  @ApiProperty({ description: '角色状态', example: 1, enum: [0, 1] })
  @IsNumber()
  @IsIn([0, 1])
  status: number;
}

export class AssignMenusDto {
  @ApiProperty({ description: '菜单ID列表', example: [1, 2, 3] })
  @IsArray()
  @IsNumber({}, { each: true })
  menuIds: number[];
} 