import { SystemAccount, SystemAccountLedgerEntryProps } from '@/domain/aggregates'
import { SystemAccountType } from '@/domain/enums'

export const SYSTEM_ACCOUNT_REPOSITORY = Symbol('ISystemAccountRepository')

export interface ISystemAccountRepository {
  // 基础 CRUD
  save(account: SystemAccount): Promise<SystemAccount>
  findById(id: bigint): Promise<SystemAccount | null>

  // 按类型查询
  findByType(accountType: SystemAccountType): Promise<SystemAccount | null>
  findByTypeAndRegion(
    accountType: SystemAccountType,
    regionCode: string,
  ): Promise<SystemAccount | null>

  // 获取或创建（用于按需生成区域系统账户）
  getOrCreate(
    accountType: SystemAccountType,
    regionCode?: string,
    regionName?: string,
  ): Promise<SystemAccount>

  // 获取所有固定系统账户
  findAllFixedAccounts(): Promise<SystemAccount[]>

  // 获取所有区域系统账户
  findAllRegionAccounts(
    accountType: SystemAccountType.SYSTEM_PROVINCE | SystemAccountType.SYSTEM_CITY,
  ): Promise<SystemAccount[]>

  // 通过钱包地址查询
  findByWalletAddress(walletAddress: string): Promise<SystemAccount | null>

  // 更新钱包地址
  updateWalletAddress(
    id: bigint,
    walletAddress: string,
    mpcPublicKey: string,
  ): Promise<void>

  // 流水相关
  saveLedgerEntry(entry: SystemAccountLedgerEntryProps): Promise<bigint>
  findLedgerEntriesByAccountId(
    accountId: bigint,
    limit?: number,
    offset?: number,
  ): Promise<SystemAccountLedgerEntryProps[]>
}
