const URL = "/one-api/mockup/purchase/transfer/";
const URL_SJ = "/one-api/mockup/purchase/suratjalan/SuratJalan/";

export async function getBranches(params) {
    try {
        var response = await axios.post(URL + "TransferRequest/getBranches", params);
        if (response.status !== 200) {
            return {
                status: "ERR",
                message: response.statusText
            }
        }

        let data = response.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        }
    }
}

export async function getStatus(params) {
    try {
        var response = await axios.post(URL + "TransferRequest/getStatus", params);

        if (response.status !== 200) {
            return {
                status: "ERR",
                message: response.statusText
            }
        }

        let data = response.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        }
    }
}

export async function search(params) {
    try {
        var response = await axios.post(URL + "TransferRequest/search", params);

        if (response.status !== 200) {
            return {
                status: "ERR",
                message: response.statusText
            }
        }

        let data = response.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        }
    }
}

export async function saveRequest(params) {
    try {
        var response = await axios.post(URL + "TransferRequest/createTfRequest", params);

        if (response.status !== 200) {
            return {
                status: "ERR",
                message: response.statusText
            }
        }

        let data = response.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        }
    }
}

export async function getListDetail(params) {
    try {
        var response = await axios.post(URL + "TransferRequest/getListDetail", params)
        if (response.status !== 200) {
            return {
                status: "ERR",
                message: response.message
            }
        }
        let data = response.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function deleteTransfer(params) {
    try {
        var response = await axios.post(URL + "TransferRequest/deleteTFRequest", params)
        if (response.status !== 200) {
            return {
                status: "ERR",
                message: response.message
            }
        }
        let data = response.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function updateTransfer(params) {
    try {
        var resp = await axios.post(URL + "TransferRequest/updateTfRequest", params)
        if (resp.status !== 200) {
            return {
                status: "ERR",
                message: resp.message
            }
        }
        let data = resp.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function getDraftDetail(params) {
    try {
        var resp = await axios.post(URL + "TransferRequest/getDraftDetail", params)
        if (resp.status !== 200) {
            return {
                status: "ERR",
                message: resp.message
            }
        }
        let data = resp.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function createSuratJalanFromTF(params) {
    try {
        var resp = await axios.post(URL_SJ + "CreateSuratJalanFromTF", params)
        if (resp.status !== 200) {
            return {
                status: "ERR",
                message: resp.message
            }
        }
        let data = resp.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function getItemBatchListing(params) {
    try {
        var resp = await axios.post(URL + "TransferRequest/getItemBatchListing", params);
        if (resp.status !== 200) {
            return {
                status: "ERR",
                message: resp.message
            }
        }

        let data = resp.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function getUnpackItemBatchListing(params) {
    try {
        var resp = await axios.post(URL + "TransferRequest/getUnpackItemBatchListing", params);
        if (resp.status !== 200) {
            return {
                status: "ERR",
                message: resp.message
            }
        }

        let data = resp.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function unpackingStock(params){
    try {
        var resp = await axios.post(URL + "TransferRequest/unpackingStock", params);
        if (resp.status !== 200) {
            return {
                status: "ERR",
                message: resp.message
            }
        }

        let data = resp.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function getUserLevel(params){
    try {
        var resp = await axios.post(URL + "TransferRequest/getUserLevel", params);
        if (resp.status !== 200) {
            return {
                status: "ERR",
                message: resp.message
            }
        }

        let data = resp.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}