import { AxiosResponse } from "axios";
import serverConnectAPI from "@/server_api/config/server-connect-api";

interface FetchAPIParams {
    apiEndpoint: string;
    skipAuth?: boolean;
    [key: string]: any;
}

const fetchAPIData = async (
    params: FetchAPIParams,
    origin?: string | null
): Promise<AxiosResponse> => {
    const {
        apiEndpoint,
        skipAuth,
        ...restParams
    } = params;

    return serverConnectAPI.get(apiEndpoint, {
        params: {
            ...restParams,
            random: "1",
        },
        skipAuth,
        ...(origin
            ? {
                headers: {
                    Origin: origin,
                },
            }
            : {}),
    });
};

export default {
    fetchAPIData,
};