"""
Event bus dependency for FastAPI routes.

This module provides the FastAPI dependency for injecting the EventBus
into route handlers. The event bus is a singleton that maintains
Redis pub/sub connections for real-time event streaming.
"""

from app.services.event_bus import (
    EventBus,
    get_connected_event_bus as _get_connected_event_bus,
)


async def get_event_bus() -> EventBus:
    """
    FastAPI dependency that provides a connected EventBus instance.

    The EventBus is a singleton that maintains Redis pub/sub connections.
    It's lazily initialized and connected on first access, and should be
    closed during application shutdown via close_event_bus().

    Usage:
        @router.get("/events/stream")
        async def stream_events(
            event_bus: EventBus = Depends(get_event_bus)
        ):
            ...

    Returns:
        EventBus: The global connected event bus instance

    Raises:
        EventBusConnectionError: If connection to Redis fails
    """
    return await _get_connected_event_bus()
