from django.contrib import admin
from django.urls import path, re_path, include
from django.conf import settings
from django.views.static import serve
from drf_spectacular.views import (
    SpectacularAPIView,
    SpectacularRedocView,
    SpectacularSwaggerView,
)

from core.health import HealthCheckView


# Root URL configuration — API-only backend
urlpatterns = [
    path(settings.ADMIN_URL_PATH, admin.site.urls),
    # Serve media uploads
    re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}),
    # Health check
    path('api/v1/health/', HealthCheckView.as_view(), name='health_check'),
    # API Schema & Documentation
    path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
    path('api/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
    path('api/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
    # Security URLs (CSRF, token refresh, etc.)
    path('api/v1/', include('core.security_urls')),
    # Feature app URLs under /api/v1/
    path('api/v1/', include('accounts.urls')),
    path('api/v1/', include('messaging.urls')),
    path('api/v1/', include('moderation.urls')),
    path('api/v1/', include('notifications.urls')),
]
