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

interface ApiRequestOptions {
  url: string;
  client: keyof typeof clientMap;
  method?: Method;
  data?: unknown;
  params?: Record<string, string | number | boolean | undefined> | object;
}

export async function apiRequest<T = unknown>(
  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;
}
