"use client";

import { api } from "@/app/services/config/api.config";
import { getData } from "./helper";

export const termServices = {
  getCategories: async (
    { page = 1, limit = 100 },
    sort = { name: 1 },
    search = null
  ) => await getData("/admin/term/categories", { page, limit }, sort, search),

  getTags: async (
    { page = 1, limit = 100 },
    sort = { name: 1 },
    search = null
  ) => await getData("/admin/term/tags", { page, limit }, sort, search),

  getChildrenById: async (id) => {
    const response = await api.post("/admin/term/categories", { data: [id] });
    return response.data;
  },

  getChildMultipleId: async (ids) => {
    const response = await api.post("/admin/term/categories", { data: ids });
    return response.data;
  },

  searchTermById: async (ids) => {
    const response = await api.post("/admin/term/tags", { data: ids });
    return response.data;
  },

  createMultipleTags: async (data) => {
    const response = await api.post("/admin/term/tags/add", { data: data });
    return response.data;
  },

  deleteCategoryById: async (id) => {
    const response = await api.post("/admin/term/categories/delete", {
      data: [id],
    });

    return response.data;
  },

  deteleMultipleCategories: async (ids) => {
    const response = await api.post("/admin/term/categories/delete", {
      data: ids,
    });
    return response.data;
  },

  deleteTagById: async (id) => {
    const response = await api.post("/admin/term/tags/delete", { data: [id] });
    return response.data[0];
  },

  deleteMultipleTag: async (ids) => {
    const response = await api.post("/admin/term/tags/delete", { data: ids });
    return response.data;
  },
};
