"""Actor package for actor registry, configuration, loading, and compilation.

Lazy-loaded to avoid pulling in heavy transitive dependencies (langchain,
langsmith, sqlalchemy, etc.) when only lightweight submodules such as
``role_validation`` or ``schema`` are needed.  The public API is unchanged:
all names listed in ``__all__`` are importable from ``cleveragents.actor``.
"""

from __future__ import annotations

import importlib
from typing import Any

__all__ = [
    "ActorCompilationError",
    "ActorConfiguration",
    "ActorLoader",
    "ActorRegistry",
    "CompilationMetadata",
    "CompiledActor",
    "InvalidEntryExitError",
    "MissingNodeError",
    "SubgraphCycleError",
    "compile_actor",
]

_LAZY_IMPORTS: dict[str, tuple[str, str]] = {
    "ActorCompilationError": (".compiler", "ActorCompilationError"),
    "CompilationMetadata": (".compiler", "CompilationMetadata"),
    "CompiledActor": (".compiler", "CompiledActor"),
    "InvalidEntryExitError": (".compiler", "InvalidEntryExitError"),
    "MissingNodeError": (".compiler", "MissingNodeError"),
    "SubgraphCycleError": (".compiler", "SubgraphCycleError"),
    "compile_actor": (".compiler", "compile_actor"),
    "ActorConfiguration": (".config", "ActorConfiguration"),
    "ActorLoader": (".loader", "ActorLoader"),
    "ActorRegistry": (".registry", "ActorRegistry"),
}


def __getattr__(name: str) -> Any:
    entry = _LAZY_IMPORTS.get(name)
    if entry is not None:
        module_path, attr_name = entry
        module = importlib.import_module(module_path, __name__)
        value = getattr(module, attr_name)
        # Cache on the module so subsequent accesses are fast
        globals()[name] = value
        return value
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
