import { IsOptional, IsString, IsEnum, IsInt, Min, Max, IsBoolean } from 'class-validator'
import { ApiPropertyOptional } from '@nestjs/swagger'
import { Type, Transform } from 'class-transformer'
import { RoleType } from '@/domain/enums'

export class QueryAuthorizationsDto {
  @ApiPropertyOptional({ description: '授权类型', enum: RoleType })
  @IsOptional()
  @IsEnum(RoleType)
  roleType?: RoleType

  @ApiPropertyOptional({ description: '搜索关键词（匹配昵称、账户序列号、地区名称）' })
  @IsOptional()
  @IsString()
  keyword?: string

  @ApiPropertyOptional({ description: '是否包含已撤销的授权', default: false })
  @IsOptional()
  @Transform(({ value }) => value === 'true' || value === true)
  @IsBoolean()
  includeRevoked?: boolean

  @ApiPropertyOptional({ description: '页码', default: 1 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page?: number

  @ApiPropertyOptional({ description: '每页数量', default: 20 })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(100)
  limit?: number
}
