from django.urls import path, include
from .viewsets import UserViewSet, GroupViewSet, PermissionViewSet
from django.conf import settings

# Define the URL patterns for the gdmty_django_users app
urlpatterns = []

try:
    # Check if DRF_ROUTER is defined in settings
    if hasattr(settings, 'DRF_ROUTER'):
        # Register viewsets with the router
        settings.DRF_ROUTER.register('/user', UserViewSet, basename='users-user')
        settings.DRF_ROUTER.register('/group', GroupViewSet, basename='users-group')
        settings.DRF_ROUTER.register('/permission', PermissionViewSet, basename='users-permission')

        # Include the URLs generated by the router
        urlpatterns += [
            path('', include(settings.DRF_ROUTER.urls)),
        ]

except AttributeError:
    # Handle cases where DRF_ROUTER is not defined in settings
    pass
