export default function useEquipmentManagement() {
  function getSupplies({
    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 getSupplyById(id: string) {
    return useNuxtApp().$api<Record<string, any>>(
      `/api/hygiene-supplies/id/${id}`,
      {
        method: "GET",
      }
    );
  }

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

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

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

  function checkOutItemSingle(site: string, id: string, payload: TStockCreate) {
    return useNuxtApp().$api<Record<string, any>>(
      `/api/hygiene-checkout-items/site/${site}/supply/${id}`,
      {
        method: "POST",
        body: {
          qty: payload.qty,
          serviceType: payload.serviceType,
        },
      }
    );
  }

  return {
    getSupplies,
    getSupplyById,
    createSupply,
    updateSupply,
    deleteSupply,
    checkOutItemSingle,

  };
}
