import { clientMap } from '@/lib/api/client-map';
import { Method } from 'axios';

interface ApiRequestOptions {
  url: string;
  client: keyof typeof clientMap;
  method?: Method;
  data?: any;
  params?: Record<string, any>;
}

export async function apiRequest<T = any>(options: ApiRequestOptions): Promise<T> {
  const { url, client, method = 'get', data, params } = options;
  const clientInstance = clientMap[client];

  if (!url || !clientInstance) {
    throw new Error(`Invalid API request: ${client} - ${url}`);
  }

  const response = await clientInstance.request<T>({ method, url, data, params });
  return response.data;
}
