import { systemConfigRoutesMt } from '@d8d/core-module-mt/system-config-module-mt';
import { rpcClient } from '@d8d/shared-ui-components/utils/hc'

export class SystemConfigClientManager {
  private static instance: SystemConfigClientManager;
  private client: ReturnType<typeof rpcClient<typeof systemConfigRoutesMt>> | null = null;

  private constructor() {}

  public static getInstance(): SystemConfigClientManager {
    if (!SystemConfigClientManager.instance) {
      SystemConfigClientManager.instance = new SystemConfigClientManager();
    }
    return SystemConfigClientManager.instance;
  }

  // 初始化客户端
  public init(baseUrl: string = '/'): ReturnType<typeof rpcClient<typeof systemConfigRoutesMt>> {
    return this.client = rpcClient<typeof systemConfigRoutesMt>(baseUrl);
  }

  // 获取客户端实例
  public get(): ReturnType<typeof rpcClient<typeof systemConfigRoutesMt>> {
    if (!this.client) {
      return this.init()
    }
    return this.client;
  }

  // 重置客户端（用于测试或重新初始化）
  public reset(): void {
    this.client = null;
  }
}

// 导出单例实例
const systemConfigClientManager = SystemConfigClientManager.getInstance();

// 导出默认客户端实例（延迟初始化）
export const systemConfigClient = systemConfigClientManager.get()

export {
  systemConfigClientManager
}