import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsOptional, IsInt, Min, Max } from 'class-validator';
import { Type } from 'class-transformer';
import { LeaderboardType } from '../../domain/value-objects/leaderboard-type.enum';

/**
 * 查询榜单请求 DTO
 */
export class QueryLeaderboardDto {
  @ApiProperty({
    enum: LeaderboardType,
    description: '榜单类型',
    example: LeaderboardType.DAILY,
  })
  @IsEnum(LeaderboardType)
  type: LeaderboardType;

  @ApiPropertyOptional({
    description: '返回数量限制',
    example: 30,
    minimum: 1,
    maximum: 100,
  })
  @IsOptional()
  @IsInt()
  @Min(1)
  @Max(100)
  @Type(() => Number)
  limit?: number;
}

/**
 * 榜单排名响应 DTO
 */
export class LeaderboardRankingResponseDto {
  @ApiProperty({ description: '排名ID' })
  id: string;

  @ApiProperty({ enum: LeaderboardType, description: '榜单类型' })
  leaderboardType: LeaderboardType;

  @ApiProperty({ description: '周期标识', example: '2024-01-15' })
  periodKey: string;

  @ApiProperty({ description: '用户ID' })
  userId: string;

  @ApiProperty({ description: '是否虚拟账户' })
  isVirtual: boolean;

  @ApiProperty({ description: '真实排名' })
  rankPosition: number;

  @ApiProperty({ description: '显示排名（含虚拟）' })
  displayPosition: number;

  @ApiPropertyOptional({ description: '上次排名' })
  previousRank: number | null;

  @ApiProperty({ description: '排名变化（正数上升，负数下降）' })
  rankChange: number;

  @ApiProperty({ description: '团队总认种量' })
  totalTeamPlanting: number;

  @ApiProperty({ description: '最大直推团队认种量' })
  maxDirectTeamPlanting: number;

  @ApiProperty({ description: '有效分值（龙虎榜分值）' })
  effectiveScore: number;

  @ApiProperty({ description: '昵称' })
  nickname: string;

  @ApiProperty({ description: '头像URL' })
  avatar: string;

  @ApiPropertyOptional({ description: '账号' })
  accountNo: string | null;

  @ApiProperty({ description: '计算时间' })
  calculatedAt: string;
}

/**
 * 我的排名响应 DTO
 */
export class MyRankingResponseDto {
  @ApiPropertyOptional({ type: LeaderboardRankingResponseDto, description: '日榜排名' })
  DAILY: LeaderboardRankingResponseDto | null;

  @ApiPropertyOptional({ type: LeaderboardRankingResponseDto, description: '周榜排名' })
  WEEKLY: LeaderboardRankingResponseDto | null;

  @ApiPropertyOptional({ type: LeaderboardRankingResponseDto, description: '月榜排名' })
  MONTHLY: LeaderboardRankingResponseDto | null;
}
