import apiClient from "@/infrastructure/apiClient";
import apiPath from "@/infrastructure/apiPath";
export default {
  async search(searchModel) {
    const params = JSON.parse(JSON.stringify(searchModel));

    var searchResult = await apiClient
      .post(apiPath.category.search, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async getTree(keyword = "", contentType = 1) {
    var searchResult = await apiClient
      .get(
        apiPath.category.getTree +
          "?keyword=" +
          keyword +
          "&contentType=" +
          contentType
      )
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async createOrUpdate(categoryModel) {
    const params = JSON.parse(JSON.stringify(categoryModel));
    var searchResult = await apiClient
      .post(apiPath.category.createOrUpdate, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async getById(id) {
    var searchResult = await apiClient
      .get(apiPath.category.getById + id)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async lock(categoryId) {
    const params = JSON.parse(JSON.stringify({ Id: categoryId }));

    var roleResult = await apiClient
      .put(apiPath.category.lock, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return roleResult;
  },
  async unlock(categoryId) {
    const params = JSON.parse(JSON.stringify({ Id: categoryId }));

    var roleResult = await apiClient
      .put(apiPath.category.unLock, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return roleResult;
  },
  async delete(categoryId) {
    var roleResult = await apiClient
      .delete(apiPath.category.delete + categoryId)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return roleResult;
  },
  async getMenuList() {
    // console.log("apiClient");
    // console.log(apiClient);
    var roleResult = await apiClient
      .get(apiPath.category.getMenuList)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return roleResult;
  },
};
