//! `bcs_rs` — high-performance Rust extension for BCS data decoding.

mod z85;

use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;

// Allow `?` on Z85Error inside #[pyfunction] bodies.
impl From<z85::Z85Error> for PyErr {
    fn from(err: z85::Z85Error) -> PyErr {
        PyValueError::new_err(err.to_string())
    }
}

#[pymodule]
mod _core {
    use super::z85;
    use pyo3::prelude::*;

    /// Decode a z85-encoded string into raw bytes (single-threaded).
    #[pyfunction]
    fn decode_z85(data: &str) -> PyResult<Vec<u8>> {
        Ok(z85::decode_scalar(data.as_bytes())?)
    }

    /// Decode a z85-encoded string into raw bytes (Rayon parallel, releases GIL).
    #[pyfunction]
    fn decode_z85_parallel(py: Python<'_>, data: &str) -> PyResult<Vec<u8>> {
        #[allow(deprecated)] // allow_threads → detach in pyo3 ≥ 0.28
        let result = py.allow_threads(|| z85::decode_parallel(data.as_bytes()));
        Ok(result?)
    }
}
