import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsBoolean, IsInt, IsOptional, IsIn, Min, Max } from 'class-validator';
import { Type } from 'class-transformer';

/**
 * 公开榜单状态响应 DTO（供移动端使用）
 */
export class LeaderboardStatusResponseDto {
  @ApiProperty({ description: '日榜开关' })
  dailyEnabled: boolean;

  @ApiProperty({ description: '周榜开关' })
  weeklyEnabled: boolean;

  @ApiProperty({ description: '月榜开关' })
  monthlyEnabled: boolean;
}

/**
 * 榜单配置响应 DTO
 */
export class LeaderboardConfigResponseDto {
  @ApiProperty({ description: '配置ID' })
  id: string;

  @ApiProperty({ description: '配置键' })
  configKey: string;

  @ApiProperty({ description: '日榜开关' })
  dailyEnabled: boolean;

  @ApiProperty({ description: '周榜开关' })
  weeklyEnabled: boolean;

  @ApiProperty({ description: '月榜开关' })
  monthlyEnabled: boolean;

  @ApiProperty({ description: '虚拟排名开关' })
  virtualRankingEnabled: boolean;

  @ApiProperty({ description: '虚拟账户数量' })
  virtualAccountCount: number;

  @ApiProperty({ description: '前端显示数量' })
  displayLimit: number;

  @ApiProperty({ description: '刷新间隔（分钟）' })
  refreshIntervalMinutes: number;
}

/**
 * 更新榜单开关请求 DTO
 */
export class UpdateLeaderboardSwitchDto {
  @ApiProperty({
    enum: ['daily', 'weekly', 'monthly'],
    description: '榜单类型',
    example: 'daily',
  })
  @IsIn(['daily', 'weekly', 'monthly'])
  type: 'daily' | 'weekly' | 'monthly';

  @ApiProperty({ description: '是否启用', example: true })
  @IsBoolean()
  enabled: boolean;
}

/**
 * 更新虚拟排名设置请求 DTO
 */
export class UpdateVirtualRankingDto {
  @ApiProperty({ description: '是否启用虚拟排名', example: false })
  @IsBoolean()
  enabled: boolean;

  @ApiProperty({
    description: '虚拟账户数量',
    example: 0,
    minimum: 0,
    maximum: 100,
  })
  @IsInt()
  @Min(0)
  @Max(100)
  @Type(() => Number)
  accountCount: number;
}

/**
 * 更新显示设置请求 DTO
 */
export class UpdateDisplaySettingsDto {
  @ApiProperty({
    description: '前端显示数量',
    example: 30,
    minimum: 1,
    maximum: 100,
  })
  @IsInt()
  @Min(1)
  @Max(100)
  @Type(() => Number)
  displayLimit: number;
}

/**
 * 更新刷新间隔请求 DTO
 */
export class UpdateRefreshIntervalDto {
  @ApiProperty({
    description: '刷新间隔（分钟）',
    example: 5,
    minimum: 1,
    maximum: 60,
  })
  @IsInt()
  @Min(1)
  @Max(60)
  @Type(() => Number)
  minutes: number;
}
