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.post.search, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async createOrUpdate(postModel) {
    const params = JSON.parse(JSON.stringify(postModel));
    var searchResult = await apiClient
      .post(apiPath.post.createOrUpdate, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async getById(id) {
    var searchResult = await apiClient
      .get(apiPath.post.getById + id)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return searchResult;
  },
  async delete(postId) {
    var roleResult = await apiClient
      .delete(apiPath.post.delete + postId)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return roleResult;
  },
  async publish(postId) {
    const params = JSON.parse(JSON.stringify({ Id: postId }));

    var jobResult = await apiClient
      .put(apiPath.post.publish, params)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return jobResult;
  },
  async callPostAi(postId) {
    var jobResult = await apiClient
      .get(apiPath.post.callPostAi + postId)
      .then((r) => {
        return r.data;
      })
      .catch((e) => {
        console.log(e);
        return {};
      });
    return jobResult;
  },
};
