"""CLI and pipeline orchestration."""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
    from ._optimizer import FunctionInput, FunctionResult, PythonOptimizer
    from ._plugin import PythonPlugin

_SUBMODULE_ATTRS: dict[str, tuple[str, str]] = {
    "FunctionInput": ("._optimizer", "FunctionInput"),
    "FunctionResult": ("._optimizer", "FunctionResult"),
    "PythonOptimizer": ("._optimizer", "PythonOptimizer"),
    "PythonPlugin": ("._plugin", "PythonPlugin"),
}


def __getattr__(name: str) -> Any:
    """Lazy-load pipeline symbols on first access."""
    if name in _SUBMODULE_ATTRS:
        import importlib  # noqa: PLC0415

        module_path, attr_name = _SUBMODULE_ATTRS[name]
        mod = importlib.import_module(module_path, __name__)
        val = getattr(mod, attr_name)
        globals()[name] = val
        return val

    msg = f"module {__name__!r} has no attribute {name!r}"
    raise AttributeError(msg)


__all__ = [
    "FunctionInput",
    "FunctionResult",
    "PythonOptimizer",
    "PythonPlugin",
]
