const URL = "/one-api/mockup/purchase/order/PurchaseOrderAset";
const URLRO = "/one-api/mockup/receive-item-po/ReceiveItemPOAsset";

async function request(endpoint, params) {
    try {
        const resp = await axios.post(URL + endpoint, params)
        if (resp.status !== 200) {
            throw new Error(resp.statusText);
        }
        return resp.data;
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function getListSupplier(params) {
    return request("/getListSupplier", params);
}

export async function getListCabang(params) {
    return request("/getListCabang", params);
}

export async function getListGudang(params) {
    return request("/getListGudang", params);
}

export async function getDaftarPoAset(params) {
    return request("/getDaftarPoAset", params);
}

export async function getDaftarAttachment(params) {
    return request("/getDaftarAttachment", params);
}

export async function getUserApproveLevel(params) {
    return request("/getUserApproveLevel", params);
}

export async function updateApprovalPO(params) {
    return request("/updateApprovalPO", params);
}

export async function getDataKontrakPoAset(params) {
    return request("/getDataKontrakPoAset", params);
}

export async function generatePOItemReceive(params) {
    try {
        const resp = await axios.post(URLRO + "/generatePOItemReceive", params)
        if (resp.status !== 200) {
            throw new Error(resp.statusText);
        }
        return resp.data;
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}
