"""Service layer package.

Class re-exports are loaded lazily (PEP 562). Importing the package itself must
stay light so that server-side consumers (compute_server) can import individual
engine submodules -- e.g. ``services.transcription_service`` -- without dragging
in GUI/client-only services (``hotkey_service`` -> PySide6), which are not part
of the headless server build. Submodule imports such as ``from services import
i18n`` continue to work unchanged.
"""
from typing import TYPE_CHECKING

# Public class name -> defining submodule (imported on first attribute access).
_LAZY_EXPORTS = {
    "BaseService": "base_service",
    "SettingsService": "settings_service",
    "AudioService": "audio_service",
    "TranscriptionService": "transcription_service",
    "ConversionService": "conversion_service",
    "HotkeyService": "hotkey_service",
    "ModelManager": "model_manager",
    "StartupService": "startup_service",
}

__all__ = list(_LAZY_EXPORTS)


def __getattr__(name: str):
    module = _LAZY_EXPORTS.get(name)
    if module is None:
        raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
    import importlib

    value = getattr(importlib.import_module(f".{module}", __name__), name)
    globals()[name] = value  # cache so subsequent access skips __getattr__
    return value


if TYPE_CHECKING:  # keep static analysers / IDEs aware of the re-exports
    from .base_service import BaseService
    from .settings_service import SettingsService
    from .audio_service import AudioService
    from .transcription_service import TranscriptionService
    from .conversion_service import ConversionService
    from .hotkey_service import HotkeyService
    from .model_manager import ModelManager
    from .startup_service import StartupService
