"""Audio capture engine abstraction layer.

Audio engines with native dependencies (WASAPI, PortAudio) are imported
inside try/except blocks so the package loads cleanly on platforms where
those libraries are unavailable (e.g. Android via Chaquopy).
"""

from ledgrab.core.audio.base import (
    AudioCaptureEngine,
    AudioCaptureStreamBase,
    AudioDeviceInfo,
)
from ledgrab.core.audio.factory import AudioEngineRegistry
from ledgrab.core.audio.analysis import (
    AudioAnalysis,
    AudioAnalyzer,
    NUM_BANDS,
    DEFAULT_SAMPLE_RATE,
    DEFAULT_CHUNK_SIZE,
)

# ── Platform-specific audio engines ─────────────────────────────────

try:
    from ledgrab.core.audio.wasapi_engine import WasapiEngine, WasapiCaptureStream

    _has_wasapi = True
except ImportError:
    _has_wasapi = False

try:
    from ledgrab.core.audio.sounddevice_engine import (
        SounddeviceEngine,
        SounddeviceCaptureStream,
    )

    _has_sounddevice = True
except ImportError:
    _has_sounddevice = False

from ledgrab.core.audio.demo_engine import DemoAudioEngine, DemoAudioCaptureStream

# Auto-register available engines
if _has_wasapi:
    AudioEngineRegistry.register(WasapiEngine)
if _has_sounddevice:
    AudioEngineRegistry.register(SounddeviceEngine)
AudioEngineRegistry.register(DemoAudioEngine)

__all__ = [
    "AudioCaptureEngine",
    "AudioCaptureStreamBase",
    "AudioDeviceInfo",
    "AudioEngineRegistry",
    "AudioAnalysis",
    "AudioAnalyzer",
    "NUM_BANDS",
    "DEFAULT_SAMPLE_RATE",
    "DEFAULT_CHUNK_SIZE",
    "DemoAudioEngine",
    "DemoAudioCaptureStream",
]

if _has_wasapi:
    __all__ += ["WasapiEngine", "WasapiCaptureStream"]
if _has_sounddevice:
    __all__ += ["SounddeviceEngine", "SounddeviceCaptureStream"]
