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

export default {
  async Search(model) {
    const params = JSON.parse(JSON.stringify(model));
    var result = await apiClient
      .post(apiPath.operation.search, params)
      .then((r) => {
        if (r.data) return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return result;
  },
  async getById(orderId) {
    var result = await apiClient
      .get(apiPath.operation.getById + `${orderId}`)
      .then((r) => {
        if (r.data) {
          return r.data;
        }
      })
      .catch((e) => {
        return {};
      });
    return result;
  },
  async pickup(model) {
    console.log(model.get("MediaList"));
    if (model != null) {
      var result = await apiClient
        .post(apiPath.operation.pickup, model, {
          headers: {
            "Content-Type": "multipart/form-data",
          },
        })
        .then((r) => {
          if (r.data) {
            return r.data;
          }
        })
        .catch((e) => {
          return {};
        });
      return result;
    }
  },
  async delivery(model) {
    if (model != null) {
      var result = await apiClient
        .post(apiPath.operation.delivery, model, {
          headers: {
            "Content-Type": "multipart/form-data",
          },
        })
        .then((r) => {
          if (r.data) {
            return r.data;
          }
        })
        .catch((e) => {
          return {};
        });
      return result;
    }
  },
};
