# users/urls.py
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import (
    UsersViewSet,
    RolesViewSet,
    UserRolesViewSet,
    UserSignupView,
    LoginUserView,
    ActivateUserView,
    GoogleAuthView,
    PasswordResetConfirmView,
    PasswordResetView,
    OfficerInviteView,
    OfficerPasswordSetupView,
    CurrentUserView,
    SyncPermissionsAPIView,
    DashboardMetricsView, 
)

router = DefaultRouter()
router.register(r"users", UsersViewSet, basename="user")
router.register(r"roles", RolesViewSet, basename="roles")
router.register(r"user-roles", UserRolesViewSet, basename="user-roles")


urlpatterns = [
    path("", include(router.urls)),
    path("signup/", UserSignupView.as_view(), name="signup"),
    path(
        "activate/<uidb64>/<token>/", ActivateUserView.as_view(), name="activate-user"
    ),
    path("login/", LoginUserView.as_view(), name="user-login"),
    path("google-auth/", GoogleAuthView.as_view(), name="google-auth"),
    path("password-reset/", PasswordResetView.as_view(), name="password-reset"),
    path(
        "password-reset-confirm/<uidb64>/<token>/",
        PasswordResetConfirmView.as_view(),
        name="password-reset-confirm",
    ),
    # This is the protected endpoint for an admin to invite an officer.
    path("officer/invite/", OfficerInviteView.as_view(), name="officer-invite"),
    # This is the public endpoint for the officer to set their password.
    # It includes the UID and token from the email link.
    path(
        "officer/password-setup/<uidb64>/<token>/",
        OfficerPasswordSetupView.as_view(),
        name="officer-password-setup",
    ),
    # --- Add this new endpoint ---
    path("user/me/", CurrentUserView.as_view(), name="current_user"),
    path(
        "permissions/sync/", SyncPermissionsAPIView.as_view(), name="sync-permissions"
    ),
    path("dashboard/metrics/", DashboardMetricsView.as_view(), name="dashboard-metrics"),
]
