"use server"

import { serverFetchBlob, serverFetchJson, serverFetchString } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api";
import { cache } from "react";
import { FileResponse } from "../reports/actions";

export interface comboProp {
  id: any;
  label: string;
}

export interface combo {
  records: comboProp[];
}
  
export const fetchSalaryCombo = cache(async () => {
    return serverFetchJson<combo>(`${BASE_API_URL}/salarys/combo`, {
      next: { tags: ["salary"] },
    });
  });

export const importSalarys = async (data: FormData) => {
    console.log("----------------",data)
    const importSalarys = await serverFetchString<String>(
        `${BASE_API_URL}/salarys/import`,
        {
            method: "POST",
            body: data,
            // headers: { "Content-Type": "multipart/form-data" },
        },
    );

    return importSalarys;
};

export const exportSalary = async () => {
  const reportBlob = await serverFetchBlob<FileResponse>(
      `${BASE_API_URL}/salarys/export`,
      {
          method: "POST",
          // body: JSON.stringify(data),
          headers: { "Content-Type": "application/json" },
      },
  );

  return reportBlob
};