import { DomainEvent } from './domain-event.base';

/**
 * 团队统计更新事件
 */
export class TeamStatisticsUpdatedEvent extends DomainEvent {
  constructor(
    public readonly userId: bigint,
    public readonly accountSequence: string,
    public readonly totalTeamCount: number,
    public readonly directReferralCount: number,
    public readonly leaderboardScore: number,
    public readonly updateReason: 'planting_added' | 'planting_removed' | 'member_joined' | 'recalculation' | 'transfer_removed' | 'transfer_added',
  ) {
    super();
  }

  get eventName(): string {
    return 'referral.team_statistics.updated';
  }

  toPayload(): Record<string, unknown> {
    return {
      eventId: this.eventId,
      eventName: this.eventName,
      occurredAt: this.occurredAt.toISOString(),
      data: {
        userId: this.userId.toString(),
        accountSequence: this.accountSequence,
        totalTeamCount: this.totalTeamCount,
        directReferralCount: this.directReferralCount,
        leaderboardScore: this.leaderboardScore,
        updateReason: this.updateReason,
      },
    };
  }
}
