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.appConfig.search, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },

  async getById(id) {
    var result = await apiClient
      .get(apiPath.appConfig.getById + id)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  },

  async createOrUpdate(model) {
    const params = JSON.parse(JSON.stringify(model));
    var result = await apiClient
      .post(apiPath.appConfig.createOrUpdate, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  },

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

  async reloadCache() {
    var result = await apiClient
      .post(apiPath.appConfig.reloadCache)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  }
};
