"""
Auth URLs — Email auth, OTP auth, Profile management, User management.
"""
from django.urls import include, path
from rest_framework.routers import DefaultRouter
from rest_framework_simplejwt.views import TokenRefreshView

from .views import (
    AvatarUploadView,
    AuthSettingsView,
    CoverUploadView,
    DetectCountryView,
    LinkPhoneView,
    LoginView,
    LogoutView,
    ProfileHistoryView,
    RegisterView,
    ResendOTPView,
    SendOTPView,
    UserListView,
    UserManagementViewSet,
    UserProfileView,
    VerifyOTPView,
)

router = DefaultRouter()
router.register('manage', UserManagementViewSet, basename='user-management')

urlpatterns = [
    # ── Email Auth ──────────────────────────────────────
    path('login/', LoginView.as_view(), name='auth-login'),
    path('register/', RegisterView.as_view(), name='auth-register'),
    path('logout/', LogoutView.as_view(), name='auth-logout'),
    path('refresh/', TokenRefreshView.as_view(), name='auth-refresh'),

    # ── OTP Auth ────────────────────────────────────────
    path('otp/send/', SendOTPView.as_view(), name='auth-otp-send'),
    path('otp/verify/', VerifyOTPView.as_view(), name='auth-otp-verify'),
    path('otp/resend/', ResendOTPView.as_view(), name='auth-otp-resend'),

    # ── Phone Linking ───────────────────────────────────
    path('phone/link/', LinkPhoneView.as_view(), name='auth-phone-link'),

    # ── Auth Settings (public) ──────────────────────────
    path('settings/', AuthSettingsView.as_view(), name='auth-settings'),
    path('detect-country/', DetectCountryView.as_view(), name='auth-detect-country'),

    # ── Users List (lookup) ─────────────────────────────
    path('users/', UserListView.as_view(), name='auth-users'),

    # ── User Management (CRUD) ──────────────────────────
    path('', include(router.urls)),

    # ── Profile ─────────────────────────────────────────
    path('profile/', UserProfileView.as_view(), name='auth-profile'),
    path('profile/avatar/', AvatarUploadView.as_view(), name='auth-avatar'),
    path('profile/cover/', CoverUploadView.as_view(), name='auth-cover'),
    path('profile/history/', ProfileHistoryView.as_view(), name='auth-profile-history'),
]
