"""
URL configuration for PX360 project.
"""

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from django.conf.urls.i18n import i18n_patterns
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
from apps.organizations.views import api_patient_search, api_staff_search

urlpatterns = [
    # Language switching
    path("i18n/", include("django.conf.urls.i18n")),
    # Admin
    path("admin/", admin.site.urls),
    # Dashboard
    path("", include("apps.dashboard.urls")),
    # Health check endpoint
    path("health/", include("apps.core.urls", namespace="health")),
    # Core pages (public submissions, hospital selection)
    path("core/", include("apps.core.urls", namespace="core")),
    # UI Pages
    path("complaints/", include("apps.complaints.urls")),
    path("inquiries/", include("apps.complaints.urls_inquiries")),
    path("physicians/", include("apps.physicians.urls", namespace="physicians")),
    path("suggestions/", include("apps.feedback.urls")),
    path("actions/", include("apps.px_action_center.urls")),
    path("executive/", include("apps.executive_summary.urls")),
    path("accounts/", include("apps.accounts.urls", namespace="accounts")),
    path("journeys/", include("apps.journeys.urls")),
    path("surveys/", include("apps.surveys.urls")),
    path("social/", include("apps.social.urls")),
    path("callcenter/", include("apps.callcenter.urls")),
    path("analytics/", include("apps.analytics.urls")),
    path("organizations/", include("apps.organizations.urls")),
    path("projects/", include("apps.projects.urls")),
    path("config/", include("apps.core.config_urls")),
    path("ai-engine/", include("apps.ai_engine.urls")),
    path("appreciation/", include("apps.appreciation.urls", namespace="appreciation")),
    path("notifications/", include("apps.notifications.urls", namespace="notifications")),
    path("observations/", include("apps.observations.urls")),
    path("px-sources/", include("apps.px_sources.urls")),
    path("references/", include("apps.references.urls", namespace="references")),
    path("standards/", include("apps.standards.urls")),
    path("reports/", include("apps.reports.urls", namespace="reports")),
    path("presentations/", include("apps.presentations.urls", namespace="presentations")),
    path("rca/", include("apps.rca.urls", namespace="rca")),
    # API endpoints
    path("api/auth/", include("apps.accounts.urls", namespace="api_auth")),
    path("api/physicians/", include("apps.physicians.urls", namespace="api_physicians")),
    path("api/integrations/", include("apps.integrations.urls")),
    path("api/notifications/", include("apps.notifications.urls", namespace="api_notifications")),
    path("api/v1/appreciation/", include("apps.appreciation.urls", namespace="api_appreciation")),
    path("api/simulator/", include("apps.simulator.urls", namespace="api_simulator")),
    path("api/patients/search/", api_patient_search, name="api_patient_search"),
    path("api/staffs/search/", api_staff_search, name="api_staff_search"),
    # External API (X-API-Key authenticated)
    path("api/v1/external/", include("apps.integrations.urls_external")),
    # OpenAPI/Swagger 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"),
]

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

# Customize admin site
admin.site.site_header = "PX360 Administration"
admin.site.site_title = "PX360 Admin Portal"
admin.site.index_title = "Welcome to PX360 Administration"
