import { apiHelpers } from "./api-local";

const uploadApi = {
  uploadFile: async (file: File, page: any | null, sheet: string | null, fileDesc: string): Promise<any> => {
    const formData = new FormData();
    formData.append("file", file);
    if (page) formData.append("page", page);
    if (sheet) formData.append("sheet", sheet);
    formData.append("file_desc", fileDesc);

    return apiHelpers.post("/upload/file", formData, {
      headers: { "Content-Type": "multipart/form-data" },
    });
  },

  processPdf: async (data: any, fileName: string, fileDesc: string): Promise<any> => {
    const payload = { ...data, fileName, fileDesc };
    return apiHelpers.post("/upload/process-pdf", payload);
  },

  saveToDatabase: async (data: any): Promise<any> => {
    return apiHelpers.post("/upload/to-postgis", data);
  },

  getStyles: async (): Promise<any> => {
    return apiHelpers.get("/dataset/styles");
  },
};

export default uploadApi;