import apiClient from "@/infrastructure/apiClient";
import apiPath from "@/infrastructure/apiPath";

export default {
  async createOrUpdate(model) {
    const params = JSON.parse(JSON.stringify(model));
    var searchResult = await apiClient
      .post(apiPath.customerAddress.createOrUpdate, params)
      .then((r) => {
        if (r.data) return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async getById(id) {
    var searchResult = await apiClient
      .get(apiPath.customerAddress.getById + id)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async delete(id) {
    var result = await apiClient
      .delete(apiPath.customerAddress.delete + id)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  },
  async suggest(keyword, customerId, type) {
    var searchResult = await apiClient
      .get(
        apiPath.customerAddress.suggest +
          `?keyword=${keyword}&customerId=${customerId}&type=${type}`
      )
      .then((r) => {
        if (r.data) {
          //console.log(r.data);
          return r.data;
        }
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async search(searchModel) {
    const params = JSON.parse(JSON.stringify(searchModel));
    var searchResult = await apiClient
      .post(apiPath.customerAddress.search, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
};
