export default function useCard() {
  function getAll({
    page = 1,
    search = "",
    limit = 10,
    status = "active",
    site = "",
    assignFilter = "available",
  } = {}) {
    return useNuxtApp().$api<Record<string, any>>(`/api/cards`, {
      method: "GET",
      query: {
        page,
        search,
        limit,
        status,
        site,
        assignFilter,
      },
    });
  }
  function add(value: any) {
    return useNuxtApp().$api<Record<string, any>>("/api/cards", {
      method: "POST",
      body: value,
    });
  }

  function deleteById(id: string) {
    return useNuxtApp().$api(`/api/cards/${id}`, {
      method: "DELETE",
    });
  }

  function updateById(id: string, value: any) {
    return useNuxtApp().$api(`/api/cards/${id}`, {
      method: "PUT",
      body: value,
    });
  }

  function replaceCard(payload: {
    cardId: string;
    issuedCardId: string;
    unitId: string;
    remarks: string;
    userId: string;
  }) {
    return useNuxtApp().$api("/api/access-management/card-replacement", {
      method: "POST",
      body: payload,
    });
  }

  return {
    getAll,
    add,
    deleteById,
    updateById,
    replaceCard,
  };
}
