import { http } from "/@/utils/http";
import { loadEnv } from "@build/index";
import { httpExport } from "/@/api/export";

const { VITE_PROXY_DOMAIN_REAL } = loadEnv();
const yewuApi = VITE_PROXY_DOMAIN_REAL + "/";

export function createHttpRequest(path: string, { url, defaultData }: {
  url: string,
  defaultData: object
} = {
    url: "",
    defaultData: {}
  }) {
  return (data: object): Promise<any> => {
    return http.request("post", `${url ? url : yewuApi}${path}`, {
      data: {
        ...defaultData,
        ...data
      }
    });
  };
}

export function createExportRequest(path: string) {
  return (data: object): Promise<any> =>
    httpExport(path, {
      data
    });
}
