/**
 * 模块化凭据服务主导出
 * 提供清晰的 API 和依赖注入支持
 */

// === 核心接口 ===
export { ICredentialService } from './interfaces/ICredentialService'
export { ICredentialRepository } from './interfaces/ICredentialRepository'
export { ISignatureProvider } from './interfaces/ISignatureProvider'

// === 主要实现 ===
export { CredentialService } from './CredentialService'
export type { CredentialServiceConfig } from './CredentialService'

// === 仓储实现 ===
export { FileCredentialRepository } from './repositories/FileCredentialRepository'

// === 签名提供者 ===
export { PacificaSignatureProvider } from './providers/PacificaSignatureProvider'

// === 工厂和构建器 ===
export {
  CredentialServiceFactory,
  CredentialServiceBuilder,
  createCredentialService,
  credentialServiceBuilder,
} from './CredentialServiceFactory'
export type { ServiceFactoryConfig } from './CredentialServiceFactory'

// === 类型定义 ===
export type { SignRequest, BatchSignRequest, SignResponse, ServiceStatus } from './interfaces/ICredentialService'

// === 共享类型 ===
export type { PlatformAccount, SignatureResult, PacificaSignData, ErrorCode } from '../shared/credential-types'

// === 便捷创建函数 ===

/**
 * 快速创建默认配置的凭据服务
 *
 * @example
 * ```typescript
 * import { quickStart } from './services';
 *
 * const service = await quickStart();
 * const response = await service.sign('pacifica', {
 *   accountId: 'main-account',
 *   data: signData
 * });
 * ```
 */
export async function quickStart(configPath?: string): Promise<ICredentialService> {
  const service = createCredentialService({ configPath })
  await service.initialize()
  return service
}

/**
 * 创建 Pacifica 专用服务实例
 *
 * @example
 * ```typescript
 * import { createPacificaService } from './services';
 *
 * const service = await createPacificaService('./credentials.json');
 * const account = service.getAccount('pacifica', 'main-account');
 * ```
 */
export async function createPacificaService(configPath?: string): Promise<ICredentialService> {
  return credentialServiceBuilder()
    .withConfigPath(configPath || './credentials.json')
    .enableWatching(true)
    .enablePerformanceTracking(true)
    .build()
}

/**
 * 创建生产环境服务实例
 *
 * @example
 * ```typescript
 * import { createProductionService } from './services';
 *
 * const service = await createProductionService({
 *   configPath: '/etc/credentials/production.json',
 *   enableWatching: false, // 生产环境不监控文件变化
 *   performanceTracking: true
 * });
 * ```
 */
export async function createProductionService(config: {
  configPath: string
  enableWatching?: boolean
  performanceTracking?: boolean
}): Promise<ICredentialService> {
  const service = credentialServiceBuilder()
    .withConfigPath(config.configPath)
    .enableWatching(config.enableWatching ?? false)
    .enablePerformanceTracking(config.performanceTracking ?? true)
    .autoInitialize(true)
    .build()

  await service.initialize()
  return service
}
