from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static


# 🔐 Superuser-only access to Django admin
def superuser_only(request):
    return request.user.is_active and request.user.is_superuser

# Override default admin permission check
admin.site.has_permission = superuser_only


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('core.urls')),
    path('inventory/', include('inventory.urls')),
    path('sales/', include('sales.urls')),
    path('accounts/', include('accounts.urls')),
    path('api/', include('api.urls', namespace='api')),
]

# Media files — both in DEBUG and production
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

# ── Custom error handlers ─────────────────────────────────────────────────────
handler400 = 'core.views.error_400'
handler403 = 'core.views.error_403'
handler404 = 'core.views.error_404'
handler500 = 'core.views.error_500'
handler503 = 'core.views.error_503'