"""
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 engine.vibes_auth.messaging.auth import JWTAuthMiddlewareStack  # noqa: E402

http_application = get_asgi_application()

messaging_urlpatters: List = []
with suppress(ModuleNotFoundError):
    from engine.vibes_auth.messaging.urls import messaging_urlpatters

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