"""Public compatibility module.

Conceptually, this module preserves the historical pipeline-oriented import
surface used by older notebooks and scripts.

It exists as a separate unit so a small stable pipeline API can remain
available while the actual implementation stays split across focused analysis
modules and is imported lazily.

It connects the legacy pipeline namespace to `coding_direction`,
`decoding_pipelines`, `dropout`, `movement`, `selection`, and `svm`.
"""

from __future__ import annotations

import importlib
from typing import Any, Dict, Tuple

_SYMBOL_SOURCES: Dict[str, Tuple[str, str]] = {
    "decode_one_bin_svm": ("svm", "decode_one_bin_svm"),
    "decode_one_bin_svm_matlab_compat": ("svm", "decode_one_bin_svm_matlab_compat"),
    "get_ccf_mask": ("selection", "get_ccf_mask"),
    "get_celltype_mask": ("selection", "get_celltype_mask"),
    "get_completion_mask": ("selection", "get_completion_mask"),
    "get_quiet_mask": ("selection", "get_quiet_mask"),
    "run_afterwhisker_decoding_pipeline": ("decoding_pipelines", "run_afterwhisker_decoding_pipeline"),
    "run_cluster_dropout_decoding": ("dropout", "run_cluster_dropout_decoding"),
    "run_coding_direction_pipeline": ("coding_direction", "run_coding_direction_pipeline"),
    "run_delay_decoding_pipeline": ("decoding_pipelines", "run_delay_decoding_pipeline"),
    "run_movement_subspace_decoding_pipeline": ("movement", "run_movement_subspace_decoding_pipeline"),
    "run_nb_neurons_decoding_pipeline": ("decoding_pipelines", "run_nb_neurons_decoding_pipeline"),
    "run_prewhisk_training_decoding_pipeline": ("decoding_pipelines", "run_prewhisk_training_decoding_pipeline"),
    "run_random_dropout_decoding": ("dropout", "run_random_dropout_decoding"),
    "run_spontlick_coding_direction_pipeline": ("coding_direction", "run_spontlick_coding_direction_pipeline"),
}

__all__ = sorted(_SYMBOL_SOURCES)


def __getattr__(name: str) -> Any:
    if name not in _SYMBOL_SOURCES:
        raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
    module_name, attr_name = _SYMBOL_SOURCES[name]
    module = importlib.import_module(f".{module_name}", __package__)
    value = getattr(module, attr_name)
    globals()[name] = value
    return value


def __dir__() -> list[str]:
    return sorted(list(globals().keys()) + __all__)
