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.product.search, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async createOrUpdate(productModel) {
    const params = JSON.parse(JSON.stringify(productModel));
    var searchResult = await apiClient
      .post(apiPath.product.createOrUpdate, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async getById(id) {
    var searchResult = await apiClient
      .get(apiPath.product.getById + id)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },

  async delete(productId) {
    var roleResult = await apiClient
      .delete(apiPath.product.delete + productId)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return roleResult;
  },
};
