export default function useScheduleTaskArea() {
  async function getAreas({
    site = "",
    search = "",
    page = 1,
    limit = 10,
  } = {}) {
    return useNuxtApp().$api<Record<string, any>>(
      "/api/hygiene-schedule-task-area",
      {
        method: "GET",
        query: {
          site,
          search,
          page,
          limit,
        },
      }
    );
  }

  function createArea(name: string, site: string) {
    return useNuxtApp().$api<Record<string, any>>(
      "/api/hygiene-schedule-task-area",
      {
        method: "POST",
        body: {
          name,
          site,
        },
      }
    );
  }

  function updateArea(id: string, name: string) {
    return useNuxtApp().$api<Record<string, any>>(
      `/api/hygiene-schedule-task-area/id/${id}`,
      {
        method: "PATCH",
        body: { name },
      }
    );
  }

  function deleteArea(id: string) {
    return useNuxtApp().$api<Record<string, any>>(
      `/api/hygiene-schedule-task-area/id/${id}`,
      {
        method: "DELETE",
      }
    );
  }

  function getAreaById(id: string) {
    return useNuxtApp().$api<Record<string, any>>(
      `/api/hygiene-schedule-task-area/id/${id}`,
      {
        method: "GET",
      }
    );
  }

  function uploadAreas(file: File, site: string) {
    const formData = new FormData();
    formData.append("file", file);
    formData.append("site", site);

    return useNuxtApp().$api<Record<string, any>>(
      "/api/hygiene-schedule-task-area/upload",
      {
        method: "POST",
        body: formData,
      }
    );
  }

  return {
    getAreas,
    createArea,
    updateArea,
    deleteArea,
    getAreaById,
    uploadAreas,
  };
}
