/**
 * 凭据服务接口
 * 定义凭据管理和签名服务的主要契约
 */

import { SignatureResult, PacificaSignData, PlatformAccount } from '../../shared/credential-types'

export interface SignRequest {
  accountId: string
  data: PacificaSignData
  requestId?: string
}

export interface BatchSignRequest {
  requests: SignRequest[]
}

export interface SignResponse {
  accountId: string
  requestId?: string
  success: boolean
  result?: SignatureResult
  error?: string
  executionTimeMs: number
}

export interface ServiceStatus {
  initialized: boolean
  configPath: string
  lastLoaded: Date
  totalAccounts: number
  platformAccounts: Record<string, number>
  performance: {
    totalSigns: number
    averageSignTime: number
    errorRate: number
  }
}

export interface ICredentialService {
  /**
   * 初始化服务
   */
  initialize(): Promise<void>

  /**
   * 执行单次签名
   */
  sign(platformId: string, request: SignRequest): Promise<SignResponse>

  /**
   * 执行批量签名
   */
  signBatch(platformId: string, batchRequest: BatchSignRequest): Promise<SignResponse[]>

  /**
   * 获取账户信息
   */
  getAccount(platformId: string, accountId: string): PlatformAccount | null

  /**
   * 获取平台的所有账户
   */
  getAccounts(platformId: string): PlatformAccount[]

  /**
   * 检查账户是否存在
   */
  hasAccount(platformId: string, accountId: string): boolean

  /**
   * 获取账户公钥
   */
  getAccountPublicKey(platformId: string, accountId: string): string | null

  /**
   * 重新加载配置
   */
  reloadConfig(): Promise<void>

  /**
   * 获取服务状态
   */
  getStatus(): ServiceStatus

  /**
   * 销毁服务
   */
  dispose(): Promise<void>
}
