"""
URL configuration for backend 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.urls import path, include
from rest_framework.routers import DefaultRouter

#from model_registry.views.ai_model_viewset import AiModelRegistryViewSet
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView

# Import View ในแอพ /api
from api.views.health_check_view import SystemHealthCheck
from api.views.audit_viewset import AuditLogViewSet

from accounts.views import CustomTokenObtainPairView

# 1. กำหนดตัวแปร router ก่อนใช้งาน
router = DefaultRouter()

# 2. ลงทะเบียน API ViewSets (Project-Level Routing)
# URL: /api/v1/audit/ (AuditLogViewSet)
router.register(
    r'audit',
    AuditLogViewSet,
    basename='auditlog',
)

# 3. ลงทะเบียน ViewSet อื่น ๆ
urlpatterns = [
    path('admin/', admin.site.urls),

    # Schema OpenAPI
    path('api/schema/', SpectacularAPIView.as_view(), name='schema'),

    # Swagger UI
    path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),

    # Redoc UI
    path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),

    # Endpoints สำหรับการยืนยันตัวตน (Login, Logout, Register)
    path("api/v1/auth/jwt/create/", CustomTokenObtainPairView.as_view(), name="jwt-create"),
    path('api/v1/auth/', include('djoser.urls')), # /users/ (Register/Update/Me), /users/set_password
    path('api/v1/auth/', include('djoser.urls.jwt')), # /jwt/create (Login), /jwt/refresh (Refresh Token)

    # Health Check Endpoint URL: /api/v1/health/
    path('api/v1/health/', SystemHealthCheck.as_view(), name='system-health'),

    # 3. รวม Router API
    path('api/v1/', include(router.urls)),
]
