import axios from "@/config/axios";
import type {
  CatalogByIdResponseType,
  CatalogResponseType,
  CreateCatalogParamsType,
  PurchaseInitiate,
  UpdateCatalogParamsType,
} from "../types/Types";

export const createCatalog = async (params: CreateCatalogParamsType) => {
  const { data } = await axios.post("/admin/catalogue", params);
  return data;
};

export const getCatalogs = async () => {
  const { data } = await axios.get<CatalogResponseType>("/admin/catalogue");
  return data;
};

export const getCatalogById = async (id: string) => {
  const { data } = await axios.get<CatalogByIdResponseType>(
    `/admin/catalogue/${id}`,
  );
  return data;
};

export const getCatalogBySlug = async (businessSlug: string, slug: string) => {
  const { data } = await axios.get<CatalogByIdResponseType>(
    `/public/catalogue/${businessSlug}/${slug}`,
  );
  return data;
};

export const updateCatalog = async (params: UpdateCatalogParamsType) => {
  const { data } = await axios.patch(`/admin/catalogue/${params.id}`, {
    content: params.content,
  });
  return data;
};

export const deleteCatalogById = async (id: string) => {
  const { data } = await axios.delete(`/admin/catalogue/${id}`);
  return data;
};

export const purchaseInitate = async (params: PurchaseInitiate) => {
  const { data } = await axios.post(
    `/admin/catalogue/purchase/initiate`,
    params,
  );
  return data;
};
