/**
 * 认种 fUSDT 注入请求事件
 * 当认种状态变为 MINING_ENABLED 时触发
 * 通知 mining-blockchain-service 从注入钱包向做市商钱包转入 fUSDT
 *
 * 转账金额 = treeCount × 5760
 */
export class AdoptionFusdtInjectionRequestedEvent {
  static readonly EVENT_TYPE = 'AdoptionFusdtInjectionRequested';
  static readonly AGGREGATE_TYPE = 'Adoption';
  /** 每棵树对应的 fUSDT 注入金额 */
  static readonly FUSDT_PER_TREE = 5760;

  constructor(
    public readonly originalAdoptionId: bigint,
    public readonly accountSequence: string,
    public readonly treeCount: number,
    public readonly adoptionDate: Date,
  ) {}

  get amount(): number {
    return this.treeCount * AdoptionFusdtInjectionRequestedEvent.FUSDT_PER_TREE;
  }

  toPayload(): Record<string, any> {
    return {
      eventType: AdoptionFusdtInjectionRequestedEvent.EVENT_TYPE,
      originalAdoptionId: this.originalAdoptionId.toString(),
      accountSequence: this.accountSequence,
      treeCount: this.treeCount,
      adoptionDate: this.adoptionDate.toISOString(),
      amount: this.amount.toString(),
      fusdtPerTree: AdoptionFusdtInjectionRequestedEvent.FUSDT_PER_TREE,
    };
  }
}
