import axios from "axios"
// import dotenv from 'dotenv';
//dotenv.config();

axios.interceptors.request.use(
    config => {
        config.headers = {
            Accept: "application/json",
            "Access-Control-Allow-Origin": "*",
        };
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);
const postAuxEnd = (path, postData, media = false) => {
    const basePath = media ? process.env.REACT_APP_EVENT_API : process.env.REACT_APP_EVENT_API
    return axios.post(`${basePath}${path}`, postData).then(res => {
        return res
    }).catch(err => {
        // throw new Error(err.response.data.message);
        throw new Error(err);
    })
}

const getAuxEnd = (path, reqData = null) => {
    const basePath = media ? process.env.REACT_APP_EVENT_API : process.env.REACT_APP_EVENT_API

    return axios.get(`${basePath}${path}`, {params: reqData}).then(res => {
        return res
        // localStorage.clear();
        // window.location.href = `/login?sessionExpired=true`;
    }).catch(err => {
        throw new Error(err);
        // throw new Error(err.response.data.message);
        // return err
    })
}

// FUNCTION TO GET SALARY RECEIVED
export const initiateDisburseRetrials = (reqData) => {
    let postData = {
        ...reqData
    }
    return postAuxEnd('/autocall/retry-disbursement', postData, false)
}
export const initiateDisburseVerify = (reqData) => {
    let postData = {
        ...reqData
    }
    return postAuxEnd('/autocall/verify-disbursement', postData, false)
}

export const initiateLoanPayment = (reqData) => {
    let postData = {
        ...reqData
    }
    return postAuxEnd('/autocall/start-repayment', postData, false)
}