#[cfg(feature = "python")]
use pyo3::exceptions::PyValueError;
#[cfg(feature = "python")]
use pyo3::prelude::*;

#[cfg(feature = "python")]
use crate::api;

#[cfg(feature = "python")]
#[pyfunction]
#[pyo3(signature = (source, *, optimize=false))]
fn simplify_expr(source: &str, optimize: bool) -> PyResult<String> {
    api::simplify_expr(source, optimize).map_err(|err| PyValueError::new_err(err.to_string()))
}

#[cfg(feature = "python")]
#[pyfunction]
#[pyo3(signature = (source, function_name="_kernel", *, optimize=false))]
fn emit_python(source: &str, function_name: &str, optimize: bool) -> PyResult<String> {
    api::emit_python(source, function_name, optimize)
        .map_err(|err| PyValueError::new_err(err.to_string()))
}

#[cfg(feature = "python")]
#[pymodule]
fn _gonidium(module: &Bound<'_, PyModule>) -> PyResult<()> {
    module.add("__version__", env!("CARGO_PKG_VERSION"))?;
    module.add_function(wrap_pyfunction!(simplify_expr, module)?)?;
    module.add_function(wrap_pyfunction!(emit_python, module)?)?;
    Ok(())
}
