/**
 * 算力记录同步事件
 * 用于同步算力明细记录到 mining-admin-service
 */
export class ContributionRecordSyncedEvent {
  static readonly EVENT_TYPE = 'ContributionRecordSynced';
  static readonly AGGREGATE_TYPE = 'ContributionRecord';

  constructor(
    public readonly originalRecordId: bigint,
    public readonly accountSequence: string,
    public readonly sourceType: string,
    public readonly sourceAdoptionId: bigint,
    public readonly sourceAccountSequence: string,
    public readonly treeCount: number,
    public readonly baseContribution: string,
    public readonly distributionRate: string,
    public readonly levelDepth: number | null,
    public readonly bonusTier: number | null,
    public readonly amount: string,
    public readonly effectiveDate: Date,
    public readonly expireDate: Date,
    public readonly isExpired: boolean,
    public readonly createdAt: Date,
  ) {}

  toPayload(): Record<string, any> {
    return {
      eventType: ContributionRecordSyncedEvent.EVENT_TYPE,
      originalRecordId: this.originalRecordId.toString(),
      accountSequence: this.accountSequence,
      sourceType: this.sourceType,
      sourceAdoptionId: this.sourceAdoptionId.toString(),
      sourceAccountSequence: this.sourceAccountSequence,
      treeCount: this.treeCount,
      baseContribution: this.baseContribution,
      distributionRate: this.distributionRate,
      levelDepth: this.levelDepth,
      bonusTier: this.bonusTier,
      amount: this.amount,
      effectiveDate: this.effectiveDate.toISOString(),
      expireDate: this.expireDate.toISOString(),
      isExpired: this.isExpired,
      createdAt: this.createdAt.toISOString(),
    };
  }
}
