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

    var roleResult = await apiClient
      .put(apiPath.lead.assignManager, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        throw new Error(e);
      });
    return roleResult;
  },
  async getReviewModel(id) {
    var searchResult = await apiClient
      .get(apiPath.lead.getReviewModel + id)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async updateReview(model) {
    const params = JSON.parse(JSON.stringify(model));
    var searchResult = await apiClient
      .put(apiPath.lead.updateReview, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
};
