"""
r4pm - Rust for process mining

Simple DataFram API
    - `df` with `import_xes`, `export_xes`, `import_ocel`, `import_ocel_pm4py`, etc.
    
Registry (for use with bindings):
    - import_item, convert_item, export_item
    - list_items, remove_item
    - item_to_df

Auto-generated bindings organized by module:
    - Import from r4pm.bindings
    - Submodules: bindings.discovery, bindings.core, etc.
"""

from .r4pm import (
    # Registry functions
    import_item,
    convert_item,
    export_item,
    list_items,
    remove_item,
    # Bindings introspection
    list_bindings,
    call_binding,
    __version__,
)

# item_to_df and import_item_from_df use PyDataFrame (pyo3-polars),
# which panics if the polars Python package is missing. Guard them here.
try:
    import polars as _polars  # noqa: F401
    from .r4pm import item_to_df, import_item_from_df
except ImportError:
    def _polars_required(*args, **kwargs):
        raise ImportError(
            "This function requires polars. Install with: pip install r4pm[polars]"
        )
    item_to_df = _polars_required
    import_item_from_df = _polars_required

__all__ = [
    # XES import/export
    "xes_import",
    "xes_export",
    # OCEL import
    "import_ocel_xml",
    "import_ocel_xml_pm4py",
    "import_ocel_json",
    "import_ocel_json_pm4py",
    "rs_ocel_to_pm4py",
    # Registry
    "import_item",
    "convert_item",
    "export_item",
    "item_to_df",
    "list_items",
    "remove_item",
    "import_item_from_df",
    # Bindings introspection
    "list_bindings",
    "call_binding",
    # Low-level Rust functions
    # "import_xes_rs",
    # "export_xes_rs",
    # "import_ocel_xml_rs",
    # "import_ocel_json_rs",
    # DataFrame submodule
    "df",
    # Bindings submodule
    "bindings",
    "__version__",
]

try:
    from . import df
except ImportError:
    class _DfNotAvailable:
        def __getattr__(self, name):
            raise ImportError(
                "r4pm.df requires polars. Install with: pip install r4pm[polars]"
            )
    df = _DfNotAvailable()

# Import bindings submodule (auto-generated by build.rs during cargo build)
try:
    from . import bindings
except ImportError:
    # Bindings not available - create a placeholder with helpful error
    class _BindingsNotGenerated:
        def __getattr__(self, name):
            raise ImportError(
                "Bindings not available. Rebuild with: maturin develop --release"
            )
    bindings = _BindingsNotGenerated()