"""
PrimeFeat: Primordial power spectrum feature detection from MCMC chains.

Recommended import patterns:

    # Core user-facing functions
    from primefeat import samples_Pk, load_chains, get_chains

    # Utilities from submodules (explicit)
    from primefeat.compute import ChainInspector, BinningConfig
    from primefeat.significance import gp_significance_test
    from primefeat.pca import perform_pca

    # Full submodule access
    import primefeat.compute as pfc
    import primefeat.gp as pfgp

For type checking only (no runtime cost):
    from typing import TYPE_CHECKING
    if TYPE_CHECKING:
        from primefeat.compute import ChainInspector
"""

from pathlib import Path
import matplotlib.pyplot as plt
from typing import TYPE_CHECKING

# ============================================================
# Public API - Only core user-facing functions
# ============================================================
from .cli import app
from .compute import samples_Pk, Rminus1, compute_ns_eff
from .load import load_chains, get_chains, get_autocorr, inspect_chains

# Submodules available via primefeat.compute, primefeat.pca, etc.
from . import compute, io, pca, gp, templates, significance, console

# ============================================================
# Type checking support (no runtime import overhead)
# ============================================================
if TYPE_CHECKING:
    # These are only imported by type checkers (Pylance, mypy)
    # Not loaded at runtime, so no performance cost
    from . import exceptions
    from . import interpolators
# ============================================================
# Public API - Minimal, only essential user-facing items
# ============================================================
__all__ = [
    # CLI
    "app",
    "main",
    # Core compute functions (most commonly used)
    "samples_Pk",
    "load_chains",
    "get_chains",
    "get_autocorr",
    "inspect_chains",
    # Analysis utilities
    "Rminus1",
    "compute_ns_eff",
    # Submodules (users do: import primefeat.compute, etc.)
    "compute",
    "pca",
    "gp",
    "templates",
    "significance",
    "plot",
    # Rich console (for advanced users)
    "console",
    "io",
]

# Note: For other utilities, import from submodules:
#   from primefeat.compute import ChainInspector, BinningConfig
#   from primefeat.gp import build_gp_covariance
#   from primefeat.pca import perform_pca


def main() -> None:
    app()


# ============================================================
# Auto-load PrimeFeat plotting style
# ============================================================
_STYLE_DIR = Path(__file__).parent
_DEFAULT_STYLE = _STYLE_DIR / "styles" / "primefeat.mplstyle"

if _DEFAULT_STYLE.exists():
    try:
        plt.style.use(str(_DEFAULT_STYLE))
    except Exception:
        # Silently fail if matplotlib style loading fails
        pass


# Import plots module after other modules are initialized to avoid circular imports
from . import plots as plot  # noqa: E402

# Export version info - read from package metadata
try:
    from importlib.metadata import version

    __version__ = version("primefeat")
except Exception:
    __version__ = "unknown"
