// client.ts — 数据层入口：构建期环境开关切换 mock / http。
import type { ApiClient } from './types';
import { MockClient } from './mock';
import { HttpClient } from './http';

export * from './types';

let singleton: ApiClient | null = null;

export function apiMode(): 'mock' | 'http' {
  return process.env.NEXT_PUBLIC_API_MODE === 'http' ? 'http' : 'mock';
}

/** 单例客户端：mock 模式保留内存状态(订阅重置/设备移除等可连续演示) */
export function getClient(): ApiClient {
  if (!singleton) singleton = apiMode() === 'http' ? new HttpClient() : new MockClient();
  return singleton;
}
