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

        var jobResult = await apiClient
            .put(apiPath.job.approve, params)
            .then((r) => {
                return r.data;
            })
            .catch((e) => {
                console.log(e);
                return {};
            });
        return jobResult;
    },
    async close(jobId) {
        const params = JSON.parse(JSON.stringify({ Id: jobId }));

        var jobResult = await apiClient
            .put(apiPath.job.close, params)
            .then((r) => {
                return r.data;
            })
            .catch((e) => {
                console.log(e);
                return {};
            });
        return jobResult;
    },
};
