/**
 * 贡献值账户更新事件
 * 当账户的 directReferralAdoptedCount, unlockedLevelDepth, unlockedBonusTiers 等字段更新时发布
 * 用于实时同步到 mining-admin-service
 */
export class ContributionAccountUpdatedEvent {
  static readonly EVENT_TYPE = 'ContributionAccountUpdated';
  static readonly AGGREGATE_TYPE = 'ContributionAccount';

  constructor(
    public readonly accountSequence: string,
    public readonly personalContribution: string,
    public readonly teamLevelContribution: string,
    public readonly teamBonusContribution: string,
    public readonly totalContribution: string,
    public readonly effectiveContribution: string,
    public readonly hasAdopted: boolean,
    public readonly directReferralAdoptedCount: number,
    public readonly unlockedLevelDepth: number,
    public readonly unlockedBonusTiers: number,
    public readonly createdAt: Date,
  ) {}

  toPayload(): Record<string, any> {
    return {
      eventType: ContributionAccountUpdatedEvent.EVENT_TYPE,
      accountSequence: this.accountSequence,
      personalContribution: this.personalContribution,
      teamLevelContribution: this.teamLevelContribution,
      teamBonusContribution: this.teamBonusContribution,
      totalContribution: this.totalContribution,
      effectiveContribution: this.effectiveContribution,
      hasAdopted: this.hasAdopted,
      directReferralAdoptedCount: this.directReferralAdoptedCount,
      unlockedLevelDepth: this.unlockedLevelDepth,
      unlockedBonusTiers: this.unlockedBonusTiers,
      createdAt: this.createdAt.toISOString(),
    };
  }
}
