from django.urls import path, include
from django.contrib.auth import views as auth_views
from rest_framework.routers import DefaultRouter
from .forms import CustomAuthenticationForm
from .views import (
    signup_view, custom_login_view, logout_view, profile_view,
    home_view, my_model_detail, uu_list, CategoryListView, search, upload_file, success,
    profile_settings_view, password_settings_view, privacy_policy, terms_conditions,
    contacts_view, about_view, settings_view, delete_bookmark, latest_uu_view, TermListView, verify_email_view, pma_detail,
    qanun_detail, report_error, uud1945_detail, toggle_bookmark,
    resend_verification_email, subscribe, TermDetailView, BookmarkViewSet,
    password_change_success, password_change_confirm, update_reading_position, submit_suggestion, reading_mode
)

# API Router
router = DefaultRouter()
router.register(r'bookmarks', BookmarkViewSet)

urlpatterns = [
    # Core Pages
    path('', home_view, name='home'),
    path('about/', about_view, name='about'),
    path('contacts/', contacts_view, name='contacts'),
    path('privacy-policy/', privacy_policy, name='privacy_policy'),
    path('terms-conditions/', terms_conditions, name='terms_conditions'),
    path('konstitusi/<uuid:uuid>/', uud1945_detail, name='uud1945_detail'),
    path('pma/<uuid:uuid>/', pma_detail, name='pma_detail'),

    # Authentication
    path('signup/', signup_view, name='signup'),
    path('login/', custom_login_view, name='login'),
    path('logout/', auth_views.LogoutView.as_view(), name='logout'),
    path('verify-email/<int:user_id>/', verify_email_view, name='verify_email'),
    path('resend-verification/<int:user_id>/', resend_verification_email, name='resend_verification'),

    # Password Management
    path('password-change-success/', password_change_success, name='password_change_success'),
    path('password-change-confirm/<int:user_id>/', password_change_confirm, name='password_change_confirm'),
    path('accounts/password_reset/', auth_views.PasswordResetView.as_view(template_name='registration/password_reset_form.html'), name='password_reset'),
    path('accounts/password_reset/done/', auth_views.PasswordResetDoneView.as_view(template_name='registration/password_reset_done.html'), name='password_reset_done'),
    path('accounts/reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name='registration/password_reset_confirm.html'), name='password_reset_confirm'),
    path('accounts/reset/done/', auth_views.PasswordResetCompleteView.as_view(template_name='registration/password_reset_complete.html'), name='password_reset_complete'),

    # User Profile
    path('profile/', profile_view, name='profile'),
    path('settings/', settings_view, name='settings'),
    path('settings/profile/', profile_settings_view, name='profile_settings'),
    path('settings/password/', password_settings_view, name='password_settings'),

    # Content Management
    path('uu/<uuid:uuid>/', my_model_detail, name='my_model_detail'),
    path('qanun/<uuid:uuid>/', qanun_detail, name='qanun_detail'),
    path('list/', uu_list, name='uu_list'),
    path('latest-uus/', latest_uu_view, name='latest_uus'),
    path('terms/', TermListView.as_view(), name='term_list'),
    path('terms/<slug:slug>/', TermDetailView.as_view(), name='term_detail'),
    path('categories/', CategoryListView.as_view(), name='categories'),
    path('report-error/', report_error, name='report_error'),
    path('accounts/', include('allauth.urls')),
    # Utilities
    path('search/', search, name='search_view'),
    path('upload/', upload_file, name='upload_file'),
    path('success/', success, name='success'),
    path('subscribe/', subscribe, name='subscribe'),
    path('bookmark/<int:pk>/', toggle_bookmark, name='toggle_bookmark'),
    path('bookmark/delete/<int:pk>/', delete_bookmark, name='delete_bookmark'),
    path('uu/<int:pk>/reading-position/', update_reading_position, name='update_reading_position'),
    path('uu/<int:pk>/suggest/', submit_suggestion, name='submit_suggestion'),
    path('uu/<uuid:uuid>/baca/',   reading_mode,      name='reading_mode'),
    # Ask / AI
    # API
    path('api/', include(router.urls)),
]
