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

export async function getSupplier(payload) {
    try {
        var response = await axios.post(URL + "getSupplier", payload);
        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 getItemCategory(payload) {
    try {
        var response = await axios.post(URL + "getItemCategory", payload);
        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 getWarehouse(payload) {
    try {
        var response = await axios.post(URL + "getWarehouse", payload);
        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 getItem(payload) {
    try {
        var response = await axios.post(URL + "getItem", payload);
        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 getItemUpdate(payload) {
    try {
        var response = await axios.post(URL + "getItemUpdate", payload);
        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 saveOrder(payload) {
    try {
        var response = await axios.post(URL + "saveOrder", payload);
        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(payload) {
    try {
        var response = await axios.post(URL + "search", payload);
        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 requestOrder(payload) {
    try {
        var response = await axios.post(URL + "requestOrder", payload);
        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 deleteOrder(payload) {
    try {
        var response = await axios.post(URL + "deleteOrder", payload);
        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 updateOrder(payload) {
    try {
        var response = await axios.post(URL + "updateOrder", payload);
        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 approvePOrder(payload) {
    try {
        var response = await axios.post(URL + "approvePOrder", payload);
        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 isValidMultipleWarehouse(payload) {
    try {
        var response = await axios.post(URL + "isValidMultipleWarehouse", payload);
        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 getPoBySupplier(payload) {
    try {
        var response = await axios.post(URL + "getPoBySupplier", payload);
        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 generateItemPO(params) {
    try {
        var response = await axios.post(URLRO + "generateItemPo", 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 getDefaultSupplierPrice(payload) {
    try {
        var response = await axios.post(URL + "getDefaultSupplierPrice", payload);
        if (response.status !== 200) {
            return {
                status: "ERR",
                message: response.statusText,
            };
        }

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