import { DomainEvent } from './domain-event.base';
import { LeaderboardType } from '../value-objects/leaderboard-type.enum';

export interface RankingChangedPayload {
  userId: bigint;
  leaderboardType: LeaderboardType;
  periodKey: string;
  previousRank: number | null;
  newRank: number;
  effectiveScore: number;
  changedAt: Date;
}

/**
 * 用户排名变化事件
 */
export class RankingChangedEvent extends DomainEvent {
  constructor(private readonly payload: RankingChangedPayload) {
    super();
  }

  get eventType(): string {
    return 'RankingChanged';
  }

  get aggregateId(): string {
    return `${this.payload.leaderboardType}_${this.payload.periodKey}_${this.payload.userId}`;
  }

  get aggregateType(): string {
    return 'LeaderboardRanking';
  }

  toPayload(): Record<string, any> {
    return {
      ...this.payload,
      userId: this.payload.userId.toString(),
    };
  }
}
