"""
URL configuration for polylan_submitter project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.http import HttpRequest
from django.shortcuts import render
from django.urls import path
from django.contrib.auth.decorators import login_required
from django.conf import settings
from django.conf.urls.static import static
from simple_cas_views import SimpleCASLoginView, SimpleCASLogoutView
from games.decorators import require_game_enabled
from market.views import market_home
from .api import api

NOITA_APP_ID = 881100
OPUS_MAGNUM_APP_ID = 558990


@login_required
def home(request: HttpRequest):
    return render(request, "home.html", {})


@login_required
@require_game_enabled(OPUS_MAGNUM_APP_ID)
def opus_magnum_home(request: HttpRequest):
    from opus_magnum.models import SteamCollection

    return render(
        request,
        "opus-magnum.html",
        {
            "collection": SteamCollection.objects.filter(is_active=True).last(),
        },
    )


@login_required
@require_game_enabled(NOITA_APP_ID)
def noita_home(request: HttpRequest):
    return render(request, "noita.html", {})


urlpatterns = [
    path("admin/", admin.site.urls),
    path("cas/login/", SimpleCASLoginView.as_view(), name="cas_ng_login"),
    path("cas/logout/", SimpleCASLogoutView.as_view(), name="cas_ng_logout"),
    path("api/", api.urls),
    path("market", market_home, name="market.home"),
    path("opus-magnum", opus_magnum_home, name="opus-magnum.home"),
    path("noita", noita_home, name="noita.home"),
    path("", home, name="home"),
]

# Serve media files in development
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
