"""Root URL configuration."""

from __future__ import annotations

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView

from simorgh.apps.platform_core.api.views import public_form
from simorgh.core.api.health import health_check

urlpatterns = [
    path("admin/", admin.site.urls),
    path("api/health/", health_check, name="health"),
    path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
    path("api/docs/", SpectacularSwaggerView.as_view(url_name="schema"), name="swagger-ui"),
    path("api/v1/", include("config.api_v1")),
    path("api/v2/", include("config.api_v2")),
    # Public form endpoint — no authentication required.
    path("f/<slug:slug>/", public_form, name="public-form"),
]

# In development, serve uploaded files stored in STORAGE_ROOT at MEDIA_URL.
# LocalFileSystemProvider saves to STORAGE_ROOT and builds URLs using MEDIA_URL,
# so the two must be served from the same root here.
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.STORAGE_ROOT)
