"""
URL configuration for RTC_DEMO project.

路由完全分离：
- /api/v1/  - App端接口（使用AppJWTAuthentication，User模型）
- /api/admin/ - Web管理端接口（使用AdminJWTAuthentication，AdminUser模型）
"""
from django.contrib import admin
from django.urls import path, include
from django.http import JsonResponse
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView


def health_check(request):
    return JsonResponse({"status": "ok"})

# ============ App端路由 (普通用户，手机一键登录) ============
app_api_patterns = [
    path('', include('apps.users.urls')),
    path('', include('apps.spirits.urls')),
    path('', include('apps.devices.urls')),
    path('', include('apps.stories.urls')),
    path('', include('apps.music.urls')),
    path('', include('apps.badge.urls')),
    path('', include('apps.notifications.urls')),
    path('', include('apps.system.urls')),
]

# ============ Web管理端路由 (管理员，用户名密码登录) ============
from apps.inventory.urls import admin_urlpatterns as inventory_admin_urls
from apps.users.urls import admin_urlpatterns as users_admin_urls
from apps.system.urls import admin_urlpatterns as system_admin_urls

admin_api_patterns = [
    # 管理员认证和个人信息
    path('', include('apps.admins.urls')),
    # 业务管理接口
    path('', include(inventory_admin_urls)),
    # App用户管理
    path('', include(users_admin_urls)),
    # 意见反馈管理
    path('', include(system_admin_urls)),
]

urlpatterns = [
    # Health check (no auth, for K8s probes)
    path('healthz/', health_check),

    # Django Admin
    path('django-admin/', admin.site.urls),
    
    # Swagger/OpenAPI文档
    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'),
    
    # App端API - 普通用户
    path('api/v1/', include(app_api_patterns)),
    
    # Web管理端API - 管理员
    path('api/admin/', include(admin_api_patterns)),
]
