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.agency.search, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async getTree(keyword) {
    var searchResult = await apiClient
      .get(apiPath.agency.getTree + keyword)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async createOrUpdate(agencyModel) {
    const params = JSON.parse(JSON.stringify(agencyModel));
    var searchResult = await apiClient
      .post(apiPath.agency.createOrUpdate, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async updateStatus(agencyModel) {
    const params = JSON.parse(JSON.stringify(agencyModel));
    var searchResult = await apiClient
      .put(apiPath.agency.updateStatus, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async getById(id) {
    var agencyModel = await apiClient
      .get(apiPath.agency.getById + id)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return agencyModel;
  },
  async delete(id) {
    var result = await apiClient
      .delete(apiPath.agency.delete + id)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  },
  async autoComplete(searchModel) {
    const params = JSON.parse(JSON.stringify(searchModel));
    var searchResult = await apiClient
      .get(apiPath.agency.autoComplete + params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
};
