"""app URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.0/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.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth.views import LogoutView
from django.urls import include, path
from django.views.generic import RedirectView
from two_factor.urls import urlpatterns as tf_urls
from two_factor.views.profile import ProfileView

from core.views import (
    ais,
    automation,
    availability,
    base,
    compose,
    groups,
    identifiers,
    instagram,
    manipulations,
    messages,
    notifications,
    osint,
    people,
    personas,
    prosody,
    queues,
    sessions,
    signal,
    system,
    tasks,
    whatsapp,
    workspace,
)

urlpatterns = [
    path(
        "favicon.ico",
        RedirectView.as_view(url=f"{settings.STATIC_URL}favicon.ico", permanent=False),
    ),
    path("", base.Home.as_view(), name="home"),
    path("admin/", admin.site.urls),
    path(
        "account/two_factor/",
        RedirectView.as_view(pattern_name="security_2fa", permanent=False),
    ),
    # 2FA login urls
    path("", include(tf_urls)),
    path("accounts/signup/", base.Signup.as_view(), name="signup"),
    path("accounts/logout/", LogoutView.as_view(), name="logout"),
    # Notifications
    path(
        "notifications/page/update/",
        RedirectView.as_view(pattern_name="notifications_settings", permanent=False),
    ),
    path(
        "notifications/<str:type>/update/",
        notifications.NotificationsUpdate.as_view(),
        name="notifications_update",
    ),
    path(
        "settings/notifications/",
        notifications.NotificationsUpdate.as_view(),
        {"type": "page"},
        name="notifications_settings",
    ),
    path(
        "settings/security/",
        system.SecurityPage.as_view(page_mode="encryption"),
        name="security_settings",
    ),
    path(
        "settings/security/encryption/",
        system.SecurityPage.as_view(page_mode="encryption"),
        name="encryption_settings",
    ),
    path(
        "settings/security/permissions/",
        system.SecurityPage.as_view(page_mode="permission"),
        name="permission_settings",
    ),
    path(
        "settings/security/permission/",
        RedirectView.as_view(pattern_name="permission_settings", permanent=False),
    ),
    path(
        "settings/security/2fa/",
        ProfileView.as_view(),
        name="security_2fa",
    ),
    path(
        "settings/accessibility/",
        system.AccessibilitySettings.as_view(),
        name="accessibility_settings",
    ),
    path(
        "settings/ai/",
        system.AISettingsPage.as_view(),
        name="ai_settings",
    ),
    path(
        "settings/modules/",
        system.ModulesSettingsPage.as_view(),
        name="modules_settings",
    ),
    path(
        "settings/system/",
        system.SystemSettings.as_view(),
        name="system_settings",
    ),
    path(
        "settings/system/capabilities/",
        system.ServiceCapabilitySnapshotAPI.as_view(),
        name="system_capabilities",
    ),
    path(
        "settings/system/adapter-health/",
        system.AdapterHealthSummaryAPI.as_view(),
        name="system_adapter_health",
    ),
    path(
        "settings/system/trace/",
        system.TraceDiagnosticsAPI.as_view(),
        name="system_trace_diagnostics",
    ),
    path(
        "settings/system/projection-shadow/",
        system.EventProjectionShadowAPI.as_view(),
        name="system_projection_shadow",
    ),
    path(
        "settings/system/event-ledger-smoke/",
        system.EventLedgerSmokeAPI.as_view(),
        name="system_event_ledger_smoke",
    ),
    path(
        "settings/system/memory-search/status/",
        system.MemorySearchStatusAPI.as_view(),
        name="system_memory_search_status",
    ),
    path(
        "settings/system/memory-search/query/",
        system.MemorySearchQueryAPI.as_view(),
        name="system_memory_search_query",
    ),
    path(
        "internal/prosody/auth/",
        prosody.ProsodyAuthBridge.as_view(),
        name="prosody_auth_bridge",
    ),
    path(
        "settings/command-routing/",
        automation.CommandRoutingSettings.as_view(),
        name="command_routing",
    ),
    path(
        "settings/ai/traces/",
        automation.AIExecutionLogSettings.as_view(),
        name="ai_execution_log",
    ),
    path(
        "settings/ai/traces/run/<int:run_id>/",
        automation.AIExecutionRunDetailView.as_view(),
        name="ai_execution_run_detail",
    ),
    path(
        "settings/ai/traces/run/<int:run_id>/tab/<str:tab_slug>/",
        automation.AIExecutionRunDetailTabView.as_view(),
        name="ai_execution_run_detail_tab",
    ),
    path(
        "settings/ai-execution/",
        RedirectView.as_view(pattern_name="ai_execution_log", permanent=False),
    ),
    path(
        "settings/translation/",
        automation.TranslationSettings.as_view(),
        name="translation_settings",
    ),
    path(
        "settings/business-plans/",
        automation.BusinessPlanInbox.as_view(),
        name="business_plan_inbox",
    ),
    path(
        "settings/business-plan/<str:doc_id>/",
        automation.BusinessPlanEditor.as_view(),
        name="business_plan_editor",
    ),
    path(
        "settings/translation/preview/",
        automation.TranslationPreview.as_view(),
        name="translation_preview",
    ),
    path(
        "services/signal/",
        signal.Signal.as_view(),
        name="signal",
    ),
    path(
        "services/whatsapp/",
        whatsapp.WhatsApp.as_view(),
        name="whatsapp",
    ),
    path(
        "services/instagram/",
        instagram.Instagram.as_view(),
        name="instagram",
    ),
    path(
        "services/signal/<str:type>/",
        signal.SignalAccounts.as_view(),
        name="signal_accounts",
    ),
    path(
        "services/whatsapp/<str:type>/",
        whatsapp.WhatsAppAccounts.as_view(),
        name="whatsapp_accounts",
    ),
    path(
        "services/instagram/<str:type>/",
        instagram.InstagramAccounts.as_view(),
        name="instagram_accounts",
    ),
    path(
        "services/signal/<str:type>/contacts/<str:pk>/",
        signal.SignalContactsList.as_view(),
        name="signal_contacts",
    ),
    path(
        "services/whatsapp/<str:type>/contacts/<str:pk>/",
        whatsapp.WhatsAppContactsList.as_view(),
        name="whatsapp_contacts",
    ),
    path(
        "services/signal/<str:type>/chats/<str:pk>/",
        signal.SignalChatsList.as_view(),
        name="signal_chats",
    ),
    path(
        "services/whatsapp/<str:type>/chats/<str:pk>/",
        whatsapp.WhatsAppChatsList.as_view(),
        name="whatsapp_chats",
    ),
    path(
        "services/signal/<str:type>/messages/<str:pk>/<str:chat_id>/",
        signal.SignalMessagesList.as_view(),
        name="signal_messages",
    ),
    path(
        "services/signal/<str:type>/add/",
        signal.SignalAccountAdd.as_view(),
        name="signal_account_add",
    ),
    path(
        "services/signal/<str:type>/unlink/<path:account>/",
        signal.SignalAccountUnlink.as_view(),
        name="signal_account_unlink",
    ),
    path(
        "services/whatsapp/<str:type>/add/",
        whatsapp.WhatsAppAccountAdd.as_view(),
        name="whatsapp_account_add",
    ),
    path(
        "services/whatsapp/<str:type>/unlink/<path:account>/",
        whatsapp.WhatsAppAccountUnlink.as_view(),
        name="whatsapp_account_unlink",
    ),
    path(
        "services/instagram/<str:type>/add/",
        instagram.InstagramAccountAdd.as_view(),
        name="instagram_account_add",
    ),
    path(
        "compose/page/",
        compose.ComposePage.as_view(),
        name="compose_page",
    ),
    path(
        "compose/workspace/",
        compose.ComposeWorkspace.as_view(),
        name="compose_workspace",
    ),
    path(
        "compose/widget/",
        compose.ComposeWidget.as_view(),
        name="compose_widget",
    ),
    path(
        "compose/workspace/widget/contacts/",
        compose.ComposeWorkspaceContactsWidget.as_view(),
        name="compose_workspace_contacts_widget",
    ),
    path(
        "compose/workspace/widget/history/",
        compose.ComposeWorkspaceHistoryWidget.as_view(),
        name="compose_workspace_history_widget",
    ),
    path(
        "compose/send/",
        compose.ComposeSend.as_view(),
        name="compose_send",
    ),
    path(
        "compose/react/",
        compose.ComposeReact.as_view(),
        name="compose_react",
    ),
    path(
        "compose/cancel-send/",
        compose.ComposeCancelSend.as_view(),
        name="compose_cancel_send",
    ),
    path(
        "compose/command-result/",
        compose.ComposeCommandResult.as_view(),
        name="compose_command_result",
    ),
    path(
        "compose/drafts/",
        compose.ComposeDrafts.as_view(),
        name="compose_drafts",
    ),
    path(
        "compose/summary/",
        compose.ComposeSummary.as_view(),
        name="compose_summary",
    ),
    path(
        "compose/quick-insights/",
        compose.ComposeQuickInsights.as_view(),
        name="compose_quick_insights",
    ),
    path(
        "compose/engage/preview/",
        compose.ComposeEngagePreview.as_view(),
        name="compose_engage_preview",
    ),
    path(
        "compose/engage/send/",
        compose.ComposeEngageSend.as_view(),
        name="compose_engage_send",
    ),
    path(
        "compose/thread/",
        compose.ComposeThread.as_view(),
        name="compose_thread",
    ),
    path(
        "compose/commands/bp/bind/",
        compose.ComposeBindBP.as_view(),
        name="compose_bind_bp",
    ),
    path(
        "compose/commands/toggle/",
        compose.ComposeToggleCommand.as_view(),
        name="compose_toggle_command",
    ),
    path(
        "compose/media/blob/",
        compose.ComposeMediaBlob.as_view(),
        name="compose_media_blob",
    ),
    path(
        "compose/widget/contacts/",
        compose.ComposeContactsDropdown.as_view(),
        name="compose_contacts_dropdown",
    ),
    path(
        "compose/contacts/match/",
        compose.ComposeContactMatch.as_view(),
        name="compose_contact_match",
    ),
    path(
        "compose/contacts/create/",
        compose.ComposeContactCreate.as_view(),
        name="compose_contact_create",
    ),
    path(
        "compose/contacts/create-all/",
        compose.ComposeContactCreateAll.as_view(),
        name="compose_contact_create_all",
    ),
    path(
        "compose/answer-suggestion/send/",
        tasks.AnswerSuggestionSend.as_view(),
        name="compose_answer_suggestion_send",
    ),
    path(
        "tasks/",
        tasks.TasksHub.as_view(),
        name="tasks_hub",
    ),
    path(
        "tasks/projects/<str:project_id>/",
        tasks.TaskProjectDetail.as_view(),
        name="tasks_project",
    ),
    path(
        "tasks/epics/<str:epic_id>/",
        tasks.TaskEpicDetail.as_view(),
        name="tasks_epic",
    ),
    path(
        "tasks/groups/<str:service>/<path:identifier>/",
        tasks.TaskGroupDetail.as_view(),
        name="tasks_group",
    ),
    path(
        "tasks/task/<str:task_id>/",
        tasks.TaskDetail.as_view(),
        name="tasks_task",
    ),
    path(
        "settings/tasks/",
        tasks.TaskSettings.as_view(),
        name="tasks_settings",
    ),
    path(
        "settings/behavioral/",
        availability.AvailabilitySettingsPage.as_view(),
        name="behavioral_signals_settings",
    ),
    path(
        "settings/availability/",
        RedirectView.as_view(pattern_name="behavioral_signals_settings", permanent=False),
        name="availability_settings",
    ),
    # AIs
    path(
        "ai/workspace/",
        workspace.AIWorkspace.as_view(),
        name="ai_workspace",
    ),
    path(
        "ai/workspace/<str:type>/contacts/",
        workspace.AIWorkspaceContactsWidget.as_view(),
        name="ai_workspace_contacts",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/",
        workspace.AIWorkspacePersonWidget.as_view(),
        name="ai_workspace_person",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/timeline/",
        workspace.AIWorkspacePersonTimelineWidget.as_view(),
        name="ai_workspace_person_timeline",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/insights/graphs/",
        workspace.AIWorkspaceInsightGraphs.as_view(),
        name="ai_workspace_insight_graphs",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/information/",
        workspace.AIWorkspaceInformation.as_view(),
        name="ai_workspace_information",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/insights/help/",
        workspace.AIWorkspaceInsightHelp.as_view(),
        name="ai_workspace_insight_help",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/insights/<str:metric>/",
        workspace.AIWorkspaceInsightDetail.as_view(),
        name="ai_workspace_insight_detail",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/run/<str:operation>/",
        workspace.AIWorkspaceRunOperation.as_view(),
        name="ai_workspace_run",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/send/",
        workspace.AIWorkspaceSendDraft.as_view(),
        name="ai_workspace_send",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/queue/",
        workspace.AIWorkspaceQueueDraft.as_view(),
        name="ai_workspace_queue",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/create/",
        workspace.AIWorkspaceCreateMitigation.as_view(),
        name="ai_workspace_mitigation_create",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/chat/",
        workspace.AIWorkspaceMitigationChat.as_view(),
        name="ai_workspace_mitigation_chat",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/export/",
        workspace.AIWorkspaceExportArtifact.as_view(),
        name="ai_workspace_mitigation_export",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/artifact/create/<str:kind>/",
        workspace.AIWorkspaceCreateArtifact.as_view(),
        name="ai_workspace_mitigation_artifact_create",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/artifact/<str:kind>/<uuid:artifact_id>/save/",
        workspace.AIWorkspaceUpdateArtifact.as_view(),
        name="ai_workspace_mitigation_artifact_save",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/artifact/<str:kind>/<uuid:artifact_id>/delete/",
        workspace.AIWorkspaceDeleteArtifact.as_view(),
        name="ai_workspace_mitigation_artifact_delete",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/artifact/<str:kind>/delete-all/",
        workspace.AIWorkspaceDeleteArtifactList.as_view(),
        name="ai_workspace_mitigation_artifact_delete_all",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/engage/share/",
        workspace.AIWorkspaceEngageShare.as_view(),
        name="ai_workspace_mitigation_engage_share",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/auto/",
        workspace.AIWorkspaceAutoSettings.as_view(),
        name="ai_workspace_mitigation_auto",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/fundamentals/save/",
        workspace.AIWorkspaceUpdateFundamentals.as_view(),
        name="ai_workspace_mitigation_fundamentals_save",
    ),
    path(
        "ai/workspace/<str:type>/person/<uuid:person_id>/mitigation/"
        "<uuid:plan_id>/meta/save/",
        workspace.AIWorkspaceUpdatePlanMeta.as_view(),
        name="ai_workspace_mitigation_meta_save",
    ),
    path(
        "settings/ai/models/",
        ais.AIList.as_view(),
        {"type": "page"},
        name="ai_models",
    ),
    path(
        "ai/models/",
        RedirectView.as_view(pattern_name="ai_models", permanent=False),
    ),
    path(
        "ai/page/",
        RedirectView.as_view(pattern_name="ai_models", permanent=False),
    ),
    path(
        "ai/<str:type>/",
        ais.AIList.as_view(),
        name="ais",
    ),
    path(
        "osint/workspace/",
        osint.OSINTWorkspace.as_view(),
        name="osint_workspace",
    ),
    path(
        "osint/workspace/widget/tabs/",
        osint.OSINTWorkspaceTabsWidget.as_view(),
        name="osint_workspace_tabs_widget",
    ),
    path(
        "ai/<str:type>/create/",
        ais.AICreate.as_view(),
        name="ai_create",
    ),
    path(
        "ai/<str:type>/update/<str:pk>/",
        ais.AIUpdate.as_view(),
        name="ai_update",
    ),
    path(
        "ai/<str:type>/delete/<str:pk>/",
        ais.AIDelete.as_view(),
        name="ai_delete",
    ),
    # People
    path(
        "person/<str:type>/",
        people.PersonList.as_view(),
        name="people",
    ),
    path(
        "person/<str:type>/create/",
        people.PersonCreate.as_view(),
        name="person_create",
    ),
    path(
        "person/<str:type>/update/<str:pk>/",
        people.PersonUpdate.as_view(),
        name="person_update",
    ),
    path(
        "person/<str:type>/delete/<str:pk>/",
        people.PersonDelete.as_view(),
        name="person_delete",
    ),
    # Groups
    path(
        "group/<str:type>/",
        groups.GroupList.as_view(),
        name="groups",
    ),
    path(
        "group/<str:type>/create/",
        groups.GroupCreate.as_view(),
        name="group_create",
    ),
    path(
        "group/<str:type>/update/<str:pk>/",
        groups.GroupUpdate.as_view(),
        name="group_update",
    ),
    path(
        "group/<str:type>/delete/<str:pk>/",
        groups.GroupDelete.as_view(),
        name="group_delete",
    ),
    # Personas
    path(
        "persona/<str:type>/",
        personas.PersonaList.as_view(),
        name="personas",
    ),
    path(
        "persona/<str:type>/create/",
        personas.PersonaCreate.as_view(),
        name="persona_create",
    ),
    path(
        "persona/<str:type>/update/<str:pk>/",
        personas.PersonaUpdate.as_view(),
        name="persona_update",
    ),
    path(
        "persona/<str:type>/delete/<str:pk>/",
        personas.PersonaDelete.as_view(),
        name="persona_delete",
    ),
    # Manipulations
    path(
        "manipulation/<str:type>/",
        manipulations.ManipulationList.as_view(),
        name="manipulations",
    ),
    path(
        "manipulation/<str:type>/create/",
        manipulations.ManipulationCreate.as_view(),
        name="manipulation_create",
    ),
    path(
        "manipulation/<str:type>/update/<str:pk>/",
        manipulations.ManipulationUpdate.as_view(),
        name="manipulation_update",
    ),
    path(
        "manipulation/<str:type>/delete/<str:pk>/",
        manipulations.ManipulationDelete.as_view(),
        name="manipulation_delete",
    ),
    # Sessions
    path(
        "session/<str:type>/",
        sessions.SessionList.as_view(),
        name="sessions",
    ),
    path(
        "session/<str:type>/create/",
        sessions.SessionCreate.as_view(),
        name="session_create",
    ),
    path(
        "session/<str:type>/update/<str:pk>/",
        sessions.SessionUpdate.as_view(),
        name="session_update",
    ),
    path(
        "session/<str:type>/delete/<str:pk>/",
        sessions.SessionDelete.as_view(),
        name="session_delete",
    ),
    # Identifiers
    path(
        "person/<str:type>/identifiers/<str:person>/",
        identifiers.PersonIdentifierList.as_view(),
        name="person_identifiers",
    ),
    path(
        "person/<str:type>/identifiers/create/<str:person>",
        identifiers.PersonIdentifierCreate.as_view(),
        name="person_identifier_create",
    ),
    path(
        "person/<str:type>/identifiers/update/<str:person>/<str:pk>/",
        identifiers.PersonIdentifierUpdate.as_view(),
        name="person_identifier_update",
    ),
    path(
        "person/<str:type>/identifiers/delete/<str:person>/<str:pk>/",
        identifiers.PersonIdentifierDelete.as_view(),
        name="person_identifier_delete",
    ),
    # Messages
    path(
        "session/<str:type>/messages/<str:session>/",
        messages.MessageList.as_view(),
        name="messages",
    ),
    path(
        "session/<str:type>/messages/create/<str:session>",
        messages.MessageCreate.as_view(),
        name="message_create",
    ),
    path(
        "session/<str:type>/messages/update/<str:session>/<str:pk>/",
        messages.MessageUpdate.as_view(),
        name="message_update",
    ),
    path(
        "session/<str:type>/messages/delete/<str:session>/<str:pk>/",
        messages.MessageDelete.as_view(),
        name="message_delete",
    ),
    # API
    # Queues
    path(
        "api/v1/queue/message/accept/<str:message_id>/",
        queues.AcceptMessageAPI.as_view(),
        name="message_accept_api",
    ),
    path(
        "api/v1/queue/message/reject/<str:message_id>/",
        queues.RejectMessageAPI.as_view(),
        name="message_reject_api",
    ),
    path(
        "queue/<str:type>/",
        queues.QueueList.as_view(),
        name="queues",
    ),
    path(
        "queue/<str:type>/create/",
        queues.QueueCreate.as_view(),
        name="queue_create",
    ),
    path(
        "queue/<str:type>/update/<str:pk>/",
        queues.QueueUpdate.as_view(),
        name="queue_update",
    ),
    path(
        "queue/<str:type>/delete/<str:pk>/",
        queues.QueueDelete.as_view(),
        name="queue_delete",
    ),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if getattr(settings, "DEBUG_TOOLBAR_ENABLED", False):
    urlpatterns.insert(0, path("__debug__/", include("debug_toolbar.urls")))
