from django.urls import path, include
from . import views
from . import page_views
from . import search_views
from . import post_views
from . import collection_views
from . import mini_apps_views
from django.views.generic import TemplateView

urlpatterns = [
    # Regular UI URLs
    path('', views.LinkListView.as_view(), name='link_list'),
    path('create/', views.LinkCreateView.as_view(), name='link_create'),
    path('update/<int:pk>/', views.LinkUpdateView.as_view(), name='link_update'),
    path('delete/<int:pk>/', views.LinkDeleteView.as_view(), name='link_delete'),
    path('delete-selected/', views.delete_selected, name='delete_selected'),
    path('detail/<int:pk>/', views.LinkDetailView.as_view(), name='link_detail'),
    path('ui/search/', search_views.SearchReactView.as_view(), name='search'),
    path('link/<int:pk>/', views.LinkDetailView.as_view(), name='link_detail'),
    path('link/<int:pk>/edit/', views.LinkUpdateView.as_view(), name='link_update'),
    path('ui/tools/', views.ToolsView.as_view(), name='tools'),
    path('tools/export-database/', views.export_database, name='export_database'),
    path('ui/help/', views.HelpView.as_view(), name='help'),
    path('ui/settings/', views.SiteSettingsView.as_view(), name='site-settings'),
    path('ui/settings/test-telegram/', views.test_telegram_view, name='test-telegram'),
    path('ui/jobs/', views.JobsView.as_view(), name='jobs'),

    # Pages
    path('ui/pages/', page_views.PageListView.as_view(), name='page-list'),
    path('ui/pages/new/', page_views.PageCreateView.as_view(), name='page-create'),
    path('ui/pages/<int:pk>/', page_views.PageDetailView.as_view(), name='page-detail'),
    path('ui/pages/<int:pk>/edit/', page_views.PageUpdateView.as_view(), name='page-update'),
    path('ui/pages/<int:pk>/delete/', page_views.PageDeleteView.as_view(), name='page-delete'),
    path('ui/pages/<int:pk>/update-tags/', page_views.update_page_tags, name='page-update-tags'),
    path('fetch-page-info/', page_views.fetch_page_info, name='fetch-page-info'),
    path('ui/screenshots/', page_views.ScreenshotGalleryView.as_view(), name='screenshot-gallery'),

    # Link task toggle API
    path('link/<int:pk>/toggle_task/', views.toggle_link_task, name='link-toggle-task'),

    # Posts
    path('ui/posts/', post_views.PostListView.as_view(), name='post-list'),
    path('ui/posts/new/', post_views.PostCreateView.as_view(), name='post-create'),
    path('ui/posts/<int:pk>/', post_views.PostDetailView.as_view(), name='post-detail'),
    path('ui/posts/<int:pk>/edit/', post_views.PostUpdateView.as_view(), name='post-update'),
    path('ui/posts/<int:pk>/delete/', post_views.PostDeleteView.as_view(), name='post-delete'),
    path('ui/posts/<int:pk>/share/', post_views.PostShareView.as_view(), name='post-share'),
    path('ui/posts/<int:post_id>/tts/', views.generate_tts, name='post-tts'),

    # Collection slideshow
    path('ui/collections/<uuid:pk>/slideshow/',
         collection_views.CollectionSlideshowView.as_view(),
         name='collection-slideshow'),

    # Mini Apps
    path('ui/mini-apps/', mini_apps_views.MiniAppsListView.as_view(), name='mini-apps-list'),
    path('ui/mini-apps/image-gallery/', mini_apps_views.ImageGalleryView.as_view(), name='mini-apps-image-gallery'),
    path('ui/mini-apps/tts/', mini_apps_views.TTSView.as_view(), name='mini-apps-tts'),
    path('ui/mini-apps/fire-planning/', mini_apps_views.FIREPlanningView.as_view(), name='mini-apps-fire-planning'),
    path('ui/mini-apps/ip-ban/', mini_apps_views.NginxIPBanView.as_view(), name='mini-apps-ip-ban'),

    # TTS API
    path('ui/tts-api/', views.generate_tts_api, name='tts-api'),

    # API Documentation
    path('ui/api-docs/',
         TemplateView.as_view(template_name='links/api_docs.html'),
         name='api-docs'),
    # Public Post URL
    path('public/posts/<int:pk>/',
         post_views.PublicPostView.as_view(),
         name='public-post'),

    # Include collection URLs
    path('', include('links.collection_urls')),
    # Include tag URLs
    path('', include('links.tag_urls')),

    # Aliases - these should always be last
    path('<str:alias>/', views.redirect_to_original, name='redirect_to_original'),
    path('<str:alias>/<str:param>/', views.redirect_to_original, name='redirect_to_original_with_param'),
    path('alias/<str:alias>/', views.LinkDetailView.as_view(), name='link_detail_by_alias'),

]
