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

from django.contrib.auth import views as auth_views

from django_project import settings
from authapp.views import profile  # Import the profile view
from dashboard.views import global_search
from django.views.generic import RedirectView


def test_500_error(request):
    """Test view to trigger 500 error - remove in production"""
    raise Exception("Test 500 error")

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', RedirectView.as_view(url='/dashboard/', permanent=False)),
    path('auth/', include('authapp.urls')),
    path('accounts/', include('allauth.urls')),  # For Google OAuth
    path('dashboard/', include('dashboard.urls')),
    path('inventory/', include('inventory.urls')),
    path('sales/', include(('sales.urls', 'sales'), namespace='sales')),
    path('customers/', include(('customers.urls', 'customers'), namespace='customers')),
    path('suppliers/', include('suppliers.urls')),
    path('settings/', include('settings.urls')),
    path('hr/', include('hr.urls')),
    path('expenses/', include('expenses.urls')),
    path('orders/', include('orders.urls')),
    path('reports/', include('reports.urls')),
    path('payments/', include('payments.urls')),
    path('shop/', include('shop.urls')),
    path('shop-backend/', include('shop_backend.urls')),
    path('customer-orders/', include('customer_orders.urls')),
    path('global-search/', global_search, name='global_search'),
    path('test-500/', test_500_error, name='test_500'),  # Remove this in production
]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)