import axios from 'axios';
import {
  Configuration,
  DefaultApi,
  JDCookieManagementApi,
  JDHistoryApi,
  JDOrderManagementApi,
  JDV2AccountApi,
  JDV2OrderApi,
  JDV2TokenManagementApi,
  JDV2PrefetchApi,
  JDV2SettingsApi
} from './generated';

// 获取API基础URL
const getApiBaseUrl = (): string => {
  if (import.meta.env.PROD) {
    return import.meta.env.VITE_API_BASE_URL || '';
  }
  return import.meta.env.VITE_API_BASE_URL || 'http://127.0.0.1:12401';
};

const configuration = new Configuration();
const apiBaseUrl = getApiBaseUrl();

export const apiClient = new DefaultApi(configuration, apiBaseUrl, axios);
export const jdCookieClient = new JDCookieManagementApi(
  configuration,
  apiBaseUrl,
  axios
);
export const jdHistoryClient = new JDHistoryApi(
  configuration,
  apiBaseUrl,
  axios
);
export const jdOrderClient = new JDOrderManagementApi(
  configuration,
  apiBaseUrl,
  axios
);
export const jdV2AccountClient = new JDV2AccountApi(
  configuration,
  apiBaseUrl,
  axios
);

export const jdV2OrderClient = new JDV2OrderApi(
  configuration,
  apiBaseUrl,
  axios
);

export const jdV2TokenClient = new JDV2TokenManagementApi(
  configuration,
  apiBaseUrl,
  axios
);
export const jdV2PrefetchClient = new JDV2PrefetchApi(
  configuration,
  apiBaseUrl,
  axios
);

export const jdV2SettingsClient = new JDV2SettingsApi(
  configuration,
  apiBaseUrl,
  axios
);
