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

from dashboard import views as dashboard_views
from template_library import views as template_views
from security.views import UnifiedLoginView
from maintenance import views as maintenance_views
from devtools import views as devtools_views
from monitoring import views as monitoring_views
from technical import views as technical_views


def home(request):
    if request.user.is_authenticated:
        if request.user.is_staff:
            return redirect("admin:index")
        return redirect("client_portal:dashboard")
    return redirect("security:login")


urlpatterns = [
    path("", UnifiedLoginView.as_view(), name="home"),
    path("health/", devtools_views.health_dashboard, name="health"),
    path("health/run/", devtools_views.health_run, name="health_run"),
    path("", include("security.urls")),
    path("portal/", include("client_portal.urls")),
    path("admin/manutencao-base-dados/", admin.site.admin_view(maintenance_views.database_maintenance_center), name="database_maintenance_center"),
    path("admin/manutencao-base-dados/<int:pk>/confirmar/", admin.site.admin_view(maintenance_views.database_maintenance_confirm), name="database_maintenance_confirm"),
    path("admin/manutencao-base-dados/<int:pk>/resultado/", admin.site.admin_view(maintenance_views.database_maintenance_result), name="database_maintenance_result"),
    path("admin/previsualizacao-clientes/", admin.site.admin_view(dashboard_views.client_preview_center), name="client_preview_center"),
    path("admin/previsualizacao-clientes/<int:pk>/iniciar/", admin.site.admin_view(dashboard_views.client_preview_start), name="client_preview_start"),
    path("portal/previsualizacao/terminar/", dashboard_views.client_preview_stop, name="client_preview_stop"),
    path("admin/credenciais-clientes/", admin.site.admin_view(dashboard_views.demo_credentials_center), name="demo_credentials_center"),
    path("admin/credenciais-clientes/exportar/", admin.site.admin_view(dashboard_views.demo_credentials_export), name="demo_credentials_export"),
    path("admin/biblioteca-templates/", admin.site.admin_view(template_views.template_center), name="template_center"),
    path("admin/biblioteca-templates/conteudo/<int:pk>/", admin.site.admin_view(template_views.reusable_template_preview), name="reusable_template_preview"),
    path("admin/biblioteca-templates/formulario/<int:pk>/", admin.site.admin_view(template_views.form_template_preview), name="form_template_preview"),
    path("admin/centro-operacoes/", admin.site.admin_view(dashboard_views.operations_center), name="operations_center"),
    path("admin/monitorizacao/", admin.site.admin_view(monitoring_views.monitoring_center), name="monitoring_center"),
    path("admin/monitorizacao/executar/", admin.site.admin_view(monitoring_views.monitoring_run), name="monitoring_run"),
    path("admin/dados-demo-wordpress/", admin.site.admin_view(technical_views.wordpress_demo_center), name="wordpress_demo_center"),
    path("admin/comunicacoes/", admin.site.admin_view(dashboard_views.communications_center), name="communications_center"),
    path("admin/qualidade-dados/", admin.site.admin_view(dashboard_views.quality_center), name="quality_center"),
    path("admin/legenda-estados/", admin.site.admin_view(dashboard_views.status_legend), name="status_legend"),
    path("admin/relatorios/", admin.site.admin_view(dashboard_views.report_center), name="report_center"),
    path("admin/relatorios/<str:report_name>/imprimir/", admin.site.admin_view(dashboard_views.report_print), name="report_print"),
    path("admin/relatorios/<str:report_name>/<str:file_format>/", admin.site.admin_view(dashboard_views.report_export), name="report_export"),
    path("admin/", admin.site.urls),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
