"""dgtw-mlflow-utils.

============
A collection of MLflow utilities for model uploading, registry management,
evaluation, and standardized naming conventions.

Usage after ``pip install``:

    from dgtw_mlflow_utils import ModelUploader, UploadConfig
    from dgtw_mlflow_utils import ModelRegistry
    from dgtw_mlflow_utils import TfMLflowEpochLogger, evaluate_model_tf
    from dgtw_mlflow_utils import NumpyMLflowLogger, evaluate_model_numpy
    from dgtw_mlflow_utils import ModelNameBuilder, Architecture, ModelVariant, Stage, RunAction
    from dgtw_mlflow_utils import compute_retrieval_metrics, compute_retrieval_metrics_numpy
"""

# --- Naming conventions (always available, no heavy deps) ----------------
from .naming import (
    Architecture,
    ModelNameBuilder,
    ModelVariant,
    ProjectPrefix,
    RunAction,
    Stage,
)

# --- Registry (requires mlflow only) -------------------------------------
from .registry import (
    ALIAS_CANARY,
    ALIAS_CHALLENGER,
    ALIAS_CHAMPION,
    ModelRegistry,
)

# --- Uploader (requires mlflow only) -------------------------------------
from .uploader import ModelUploader, UploadConfig

# --- TensorFlow-dependent modules (lazy imports) --------------------------
# These are imported lazily to avoid requiring TensorFlow at import time.
# Users can still do: from dgtw_mlflow_utils import TfMLflowEpochLogger
# But TensorFlow is only needed when the class is actually used.

_LAZY_IMPORTS = {
    "TfMLflowEpochLogger": (".evaluator", "TfMLflowEpochLogger"),
    "NumpyMLflowLogger": (".evaluator", "NumpyMLflowLogger"),
    "evaluate_model_tf": (".evaluator", "evaluate_model_tf"),
    "evaluate_model_numpy": (".evaluator", "evaluate_model_numpy"),
    "compute_retrieval_metrics": (".metrics", "compute_retrieval_metrics"),
    "compute_retrieval_metrics_numpy": (".metrics", "compute_retrieval_metrics_numpy"),
}


def __getattr__(name):
    """Lazy-import TensorFlow-dependent symbols on first access."""
    if name in _LAZY_IMPORTS:
        module_path, attr = _LAZY_IMPORTS[name]
        import importlib

        mod = importlib.import_module(module_path, package=__name__)
        value = getattr(mod, attr)
        # Cache it so subsequent accesses don't re-import
        globals()[name] = value
        return value

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


__all__ = [
    "ALIAS_CANARY",
    "ALIAS_CHALLENGER",
    "ALIAS_CHAMPION",
    # naming
    "Architecture",
    "ModelNameBuilder",
    # registry
    "ModelRegistry",
    # uploader
    "ModelUploader",
    "ModelVariant",
    "NumpyMLflowLogger",
    "ProjectPrefix",
    "RunAction",
    "Stage",
    # evaluator (lazy)
    "TfMLflowEpochLogger",
    "UploadConfig",
    # metrics (lazy)
    "compute_retrieval_metrics",
    "compute_retrieval_metrics_numpy",
    "evaluate_model_numpy",
    "evaluate_model_tf",
]

__version__ = "0.1.0"
