"""
URL configuration for igny8_core project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from drf_spectacular.views import (
    SpectacularAPIView,
    SpectacularRedocView,
    SpectacularSwaggerView,
)
from igny8_core.auth.views import (
    industry_csv_template, industry_csv_import,
    industrysector_csv_template, industrysector_csv_import,
    seedkeyword_csv_template, seedkeyword_csv_import
)

urlpatterns = [
    # CSV Import/Export for admin - MUST come before admin/ to avoid being caught by admin.site.urls
    path('admin/igny8_core_auth/industry/csv-template/', industry_csv_template, name='admin_industry_csv_template'),
    path('admin/igny8_core_auth/industry/csv-import/', industry_csv_import, name='admin_industry_csv_import'),
    path('admin/igny8_core_auth/industrysector/csv-template/', industrysector_csv_template, name='admin_industrysector_csv_template'),
    path('admin/igny8_core_auth/industrysector/csv-import/', industrysector_csv_import, name='admin_industrysector_csv_import'),
    path('admin/igny8_core_auth/seedkeyword/csv-template/', seedkeyword_csv_template, name='admin_seedkeyword_csv_template'),
    path('admin/igny8_core_auth/seedkeyword/csv-import/', seedkeyword_csv_import, name='admin_seedkeyword_csv_import'),
    path('admin/', admin.site.urls),
    path('api/v1/auth/', include('igny8_core.auth.urls')),  # Auth endpoints
    path('api/v1/account/', include('igny8_core.api.urls')),  # Account management (settings, team, usage)
    path('api/v1/planner/', include('igny8_core.modules.planner.urls')),
    path('api/v1/writer/', include('igny8_core.modules.writer.urls')),
    path('api/v1/system/', include('igny8_core.modules.system.urls')),
    path('api/v1/billing/', include('igny8_core.business.billing.urls')),  # Billing (credits, invoices, payments, packages)
    path('api/v1/admin/', include('igny8_core.modules.billing.admin_urls')),  # Admin billing
    path('api/v1/automation/', include('igny8_core.business.automation.urls')),  # Automation endpoints
    path('api/v1/linker/', include('igny8_core.modules.linker.urls')),  # Linker endpoints
    path('api/v1/optimizer/', include('igny8_core.modules.optimizer.urls')),  # Optimizer endpoints
    path('api/v1/publisher/', include('igny8_core.modules.publisher.urls')),  # Publisher endpoints
    path('api/v1/integration/', include('igny8_core.modules.integration.urls')),  # Integration endpoints
    # OpenAPI Schema and Documentation
    path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
    path('api/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
    path('api/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
]

# Error handlers
handler400 = 'django.views.defaults.bad_request'
handler403 = 'django.views.defaults.permission_denied'
handler404 = 'django.views.defaults.page_not_found'
handler500 = 'django.views.defaults.server_error'
