export default function usePromoCode() {
  function add(value: TPromoCode) {
    return useNuxtApp().$api<Record<string, any>>("/api/promo-codes", {
      method: "POST",
      body: value,
    });
  }

  function getPromoCodes({ search = "", page = 1, status = "active" } = {}) {
    return useNuxtApp().$api<Record<string, any>>("/api/promo-codes", {
      method: "GET",
      query: {
        search,
        page,
        status,
      },
    });
  }

  function getByCode(code: string, type?: string, assigned?: boolean) {
    return useNuxtApp().$api<Record<string, any>>("/api/promo-codes/code", {
      method: "GET",
      params: {
        code,
        type,
        assigned,
      },
    });
  }

  return {
    add,
    getPromoCodes,
    getByCode,
  };
}
