"""
ASGI config for the eVibes project with Django Channels.

Exposes the ASGI callable as a module-level variable named ``application``.
"""

import os
from contextlib import suppress
from typing import List

import django
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "evibes.settings")
django.setup()

from vibes_auth.messaging.auth import JWTAuthMiddlewareStack  # noqa: E402

http_application = get_asgi_application()

websocket_urlpatterns: List = []
with suppress(ModuleNotFoundError):
    from vibes_auth.messaging.routing import websocket_urlpatterns

application = ProtocolTypeRouter(
    {
        "http": http_application,
        "websocket": JWTAuthMiddlewareStack(URLRouter(websocket_urlpatterns)),
    }
)
