from django.urls import include, path
from rest_framework.routers import DefaultRouter
from rest_framework_simplejwt.views import TokenRefreshView

from .views import (
    AcknowledgementChecklistItemViewSet,
    AcknowledgementContentViewSet,
    CustomTokenObtainPairView,
    RoleViewSet,
    UserAcknowledgementViewSet,
    UserViewSet,
    user_settings,
)
from .ui_views import (
    acknowledgement_checklist_list,
    acknowledgement_content_list,
    change_password_view,
    CustomPasswordResetConfirmView,
    login_view,
    logout_view,
    onboarding_complete,
    onboarding_step_activation,
    onboarding_step_checklist,
    onboarding_step_content,
    onboarding_welcome,
    password_reset_view,
    provisional_user_list,
    provisional_user_progress,
)

app_name = 'accounts'

router = DefaultRouter()
router.register(r'users', UserViewSet, basename='user')
router.register(r'roles', RoleViewSet, basename='role')
router.register(r'onboarding/content', AcknowledgementContentViewSet, basename='acknowledgement-content')
router.register(r'onboarding/checklist', AcknowledgementChecklistItemViewSet, basename='acknowledgement-checklist')
router.register(r'onboarding/acknowledgements', UserAcknowledgementViewSet, basename='user-acknowledgement')

urlpatterns = [
    # UI Authentication URLs
    path('login/', login_view, name='login'),
    path('logout/', logout_view, name='logout'),
    path('settings/', user_settings, name='settings'),
    path('password/reset/', password_reset_view, name='password_reset'),
    path('password/reset/confirm/<uidb64>/<token>/', CustomPasswordResetConfirmView.as_view(), name='password_reset_confirm'),
    path('password/change/', change_password_view, name='password_change'),
    
    # JWT Authentication
    path('token/', CustomTokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
    
    # User and Role endpoints
    path('', include(router.urls)),
    
    # Onboarding Wizard UI
    path('onboarding/welcome/', onboarding_welcome, name='onboarding-welcome'),
    path('onboarding/wizard/step/<int:step>/', onboarding_step_content, name='onboarding-step-content'),
    path('onboarding/wizard/checklist/', onboarding_step_checklist, name='onboarding-step-checklist'),
    path('onboarding/wizard/activation/', onboarding_step_activation, name='onboarding-step-activation'),
    path('onboarding/complete/', onboarding_complete, name='onboarding-complete'),
    
    # Provisional User Management
    path('onboarding/provisional/', provisional_user_list, name='provisional-user-list'),
    path('onboarding/provisional/<uuid:user_id>/progress/', provisional_user_progress, name='provisional-user-progress'),
    
    # Acknowledgement Management
    path('onboarding/content/', acknowledgement_content_list, name='acknowledgement-content-list'),
    path('onboarding/checklist-items/', acknowledgement_checklist_list, name='acknowledgement-checklist-list'),
]
