export default function useEquipment() {
  function getEquipments({ page = 1, search = "", limit = 10, site = "", serviceType = "" } = {}) {
    return useNuxtApp().$api<Record<string, any>>(
      `/api/hygiene-supplies/site/${site}`,
      {
        method: "GET",
        query: { page, search, limit, site, serviceType },
      }
    );
  }

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

  function createEquipment(payload: TEquipmentCreate, site: string, serviceType = "") {
    return useNuxtApp().$api<Record<string, any>>(
      `/api/hygiene-supplies/site/${site}`,
      {
        method: "POST",
        body: {
          name: payload.name,
          unitOfMeasurement: payload.unitOfMeasurement,
          serviceType,
        },
      }
    );
  }

  function updateEquipment(id: string, payload: TEquipmentCreate) {
    return useNuxtApp().$api<Record<string, any>>(
      `/api/hygiene-supplies/id/${id}`,
      {
        method: "PATCH",
        body: {
          name: payload.name,
          unitOfMeasurement: payload.unitOfMeasurement,
        },
      }
    );
  }

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

  return {
    getEquipments,
    getEquipmentById,
    createEquipment,
    updateEquipment,
    deleteEquipment,
  };
}
