import { DomainEvent } from './domain-event.base'
import { SystemAccountType, SystemLedgerEntryType } from '@/domain/enums'

// 系统账户创建事件
export class SystemAccountCreatedEvent extends DomainEvent {
  readonly eventType = 'SystemAccountCreated'
  readonly aggregateId: string
  readonly payload: {
    accountType: SystemAccountType
    regionCode: string | null
  }

  constructor(params: { accountType: SystemAccountType; regionCode: string | null }) {
    super()
    this.aggregateId = `${params.accountType}:${params.regionCode || 'global'}`
    this.payload = params
  }
}

// 系统账户钱包生成事件
export class SystemAccountWalletGeneratedEvent extends DomainEvent {
  readonly eventType = 'SystemAccountWalletGenerated'
  readonly aggregateId: string
  readonly payload: {
    accountId: string
    accountType: SystemAccountType
    walletAddress: string
    mpcPublicKey: string
  }

  constructor(params: {
    accountId: string
    accountType: SystemAccountType
    walletAddress: string
    mpcPublicKey: string
  }) {
    super()
    this.aggregateId = params.accountId
    this.payload = params
  }
}

// 系统账户收到资金事件
export class SystemAccountFundsReceivedEvent extends DomainEvent {
  readonly eventType = 'SystemAccountFundsReceived'
  readonly aggregateId: string
  readonly payload: {
    accountId: string
    accountType: SystemAccountType
    amount: string
    entryType: SystemLedgerEntryType
    balanceAfter: string
  }

  constructor(params: {
    accountId: string
    accountType: SystemAccountType
    amount: string
    entryType: SystemLedgerEntryType
    balanceAfter: string
  }) {
    super()
    this.aggregateId = params.accountId
    this.payload = params
  }
}

// 系统账户转出资金事件
export class SystemAccountFundsTransferredEvent extends DomainEvent {
  readonly eventType = 'SystemAccountFundsTransferred'
  readonly aggregateId: string
  readonly payload: {
    accountId: string
    accountType: SystemAccountType
    amount: string
    txHash: string | null
    balanceAfter: string
  }

  constructor(params: {
    accountId: string
    accountType: SystemAccountType
    amount: string
    txHash: string | null
    balanceAfter: string
  }) {
    super()
    this.aggregateId = params.accountId
    this.payload = params
  }
}
