import { LeaderboardRanking } from '../aggregates/leaderboard-ranking/leaderboard-ranking.aggregate';
import { LeaderboardType } from '../value-objects/leaderboard-type.enum';

/**
 * 龙虎榜排名仓储接口
 */
export interface ILeaderboardRankingRepository {
  /**
   * 保存单个排名
   */
  save(ranking: LeaderboardRanking): Promise<void>;

  /**
   * 批量保存排名
   */
  saveAll(rankings: LeaderboardRanking[]): Promise<void>;

  /**
   * 根据ID查找排名
   */
  findById(id: bigint): Promise<LeaderboardRanking | null>;

  /**
   * 根据榜单类型和周期查找排名列表
   */
  findByTypeAndPeriod(
    type: LeaderboardType,
    periodKey: string,
    options?: {
      limit?: number;
      includeVirtual?: boolean;
    },
  ): Promise<LeaderboardRanking[]>;

  /**
   * 查找用户在特定榜单的排名
   */
  findUserRanking(
    type: LeaderboardType,
    periodKey: string,
    userId: bigint,
  ): Promise<LeaderboardRanking | null>;

  /**
   * 查找用户在上一个周期的排名（用于计算排名变化）
   */
  findUserPreviousRanking(
    type: LeaderboardType,
    userId: bigint,
  ): Promise<LeaderboardRanking | null>;

  /**
   * 删除特定榜单周期的所有排名
   */
  deleteByTypeAndPeriod(
    type: LeaderboardType,
    periodKey: string,
  ): Promise<void>;

  /**
   * 统计特定榜单周期的参与人数
   */
  countByTypeAndPeriod(
    type: LeaderboardType,
    periodKey: string,
  ): Promise<number>;

  /**
   * 获取特定榜单周期的最高分
   */
  getTopScore(
    type: LeaderboardType,
    periodKey: string,
  ): Promise<number>;
}

export const LEADERBOARD_RANKING_REPOSITORY = Symbol('ILeaderboardRankingRepository');
