# -*- coding: utf-8 -*-
"""
Adtlas Core URL Configuration

This module defines the main URL routing for the Adtlas DAI Management System. 
including all app URLs, admin interface, static/media files,
and error handlers.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.2/topics/http/urls/

URL Structure:
    - / : Core app (landing pages, dashboard)
    - /admin/ : Django admin interface
    - /accounts/ : User management and profiles
    - /auth/ : Authentication and authorization
    - /api/ : API endpoints

Features:
    - Comprehensive URL routing for all apps
    - Static and media file serving in development
    - Custom error handlers
    - API versioning support
    - Internationalization support

"""

from django.contrib import admin
from django.conf import settings 
from django.views.static import serve 
from django.conf.urls.static import static
from django.views.generic import RedirectView, TemplateView
from django.urls import path, include, re_path
from django.conf.urls.i18n import i18n_patterns
from django.views.i18n import JavaScriptCatalog
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods


# Main URL patterns (language-independent)
urlpatterns = [
    # Django Admin Interface
    path("admin/", admin.site.urls),
    
    # Prometheus metrics endpoint
    path("", include("django_prometheus.urls")),

    # Core application URLs
    path("", include("apps.core.urls")),

    # Authentication URLs (without namespace to avoid duplication)
    path("auth/", include("apps.authentication.urls")),

    # Accounts URLs (without namespace to avoid duplication)
    path("accounts/", include("apps.accounts.urls")),

    # # Campaign management URLs
    # path("campaigns/", include("apps.campaigns.urls", namespace="campaigns")),
    
    # # Advertiser management URLs
    # path("advertisers/", include("apps.advertisers.urls", namespace="advertisers")),
    
    # # Channel management URLs
    # path("channels/", include("apps.channels.urls", namespace="channels")),

#     # # 
#     # path("agency/", include("apps.agencies.urls", namespace="agency")),
    
#     # # Ad spot management URLs
#     # path("adspots/", include("apps.adspots.urls")),
    
#     # # Playlist management URLs
#     # path("playlists/", include("apps.playlists.urls")),
    
#     # # Analytics and reporting URLs
#     # path("analytics/", include("apps.analytics.urls")),

#     # # VAST protocol URLs
#     # path("vast/", include("apps.vast.urls")),

    # Internationalization
    path("i18n/", include("django.conf.urls.i18n")),
    path("jsi18n/", JavaScriptCatalog.as_view(), name="javascript-catalog"), 
    # Favicon redirect
    path("favicon.ico", RedirectView.as_view(url="/static/favicon.ico", permanent=True)), 
    # Robots.txt
    path("robots.txt", RedirectView.as_view(url="/static/robots.txt", permanent=True)),

    # # API endpoints (version 1)
    # path("api/v1/", include([
    #     path("accounts/", include("apps.accounts.urls")),
    #     path("auth/", include("apps.authentication.urls")),
    #     path("core/", include("apps.core.urls")),
    #     path("campaigns/", include("apps.campaigns.api_urls")),
    #     path("advertisers/", include("apps.advertisers.api_urls")),
    #     path("channels/", include("apps.channels.api_urls")),
    #     path("adspots/", include("apps.adspots.api_urls")),
    #     path("playlists/", include("apps.playlists.api_urls")),
    #     path("analytics/", include("apps.analytics.api_urls")),
    #     path("vast/", include("apps.vast.api_urls")),
    # ])),
]

# # Language-specific URL patterns
# urlpatterns += i18n_patterns(
#     # Core app (landing pages, dashboard)
#     path("", include("apps.core.urls", namespace="core")),
    
#     # User accounts and profiles
#     path("accounts/", include("apps.accounts.urls", namespace="accounts")),
    
#     # Authentication and authorization
#     path("auth/", include("apps.authentication.urls", namespace="auth")),
    
#     # Prefix for language-specific URLs
#     prefix_default_language=False,
# )

# Development settings for static and media files
if settings.DEBUG:
    # Serve static files during development
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    # Serve media files during development
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    # Django Debug Toolbar (if installed)
    try:
        import debug_toolbar
        urlpatterns = [
            path("__debug__/", include(debug_toolbar.urls)),
        ] + urlpatterns
    except ImportError:
        pass
else:
    urlpatterns.extend([
        path(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
        path(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATICFILES_DIRS}),
    ])

# Custom error handlers
handler404 = "apps.core.views.handler404"
handler500 = "apps.core.views.handler500"
handler403 = "apps.core.views.handler403"
handler400 = "apps.core.views.handler400"

# Admin site customization
admin.site.site_header = "Adtlas DAI Management"
admin.site.site_title = "Adtlas Admin"
admin.site.index_title = "Welcome to Adtlas Administration"
