import { advertisementTypeRoutes } from '@d8d/advertisements-module-mt';
import { rpcClient } from '@d8d/shared-ui-components/utils/hc'

class AdvertisementTypeClientManager {
  private static instance: AdvertisementTypeClientManager;
  private client: ReturnType<typeof rpcClient<typeof advertisementTypeRoutes>> | null = null;

  private constructor() {}

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

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

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

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

// 导出单例实例
const advertisementTypeClientManager = AdvertisementTypeClientManager.getInstance();

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

export {
  advertisementTypeClientManager
}