from django.urls import include, path

from apps.core.views.views import FSMTransitionView
from apps.rides.views import ParkSingleCategoryListView

from . import views, views_search
from .views_roadtrip import (
    CreateTripView,
    FindParksAlongRouteView,
    GeocodeAddressView,
    ParkDistanceCalculatorView,
    RoadTripPlannerView,
    TripDetailView,
)

app_name = "parks"

urlpatterns = [
    # Park views with autocomplete search
    path("", views.ParkListView.as_view(), name="park_list"),
    path("operators/", views.OperatorListView.as_view(), name="operator_list"),
    path("create/", views.ParkCreateView.as_view(), name="park_create"),
    # Add park button endpoint (moved before park detail pattern)
    path("add-park-button/", views.add_park_button, name="add_park_button"),
    # Location search endpoints
    path("search/location/", views.location_search, name="location_search"),
    path(
        "search/reverse-geocode/",
        views.reverse_geocode,
        name="reverse_geocode",
    ),
    # Areas and search endpoints for HTMX
    path("areas/", views.get_park_areas, name="get_park_areas"),
    path("suggest_parks/", views_search.suggest_parks, name="suggest_parks"),
    path("search/", views.search_parks, name="search_parks"),
    # Road trip planning URLs
    path("roadtrip/", RoadTripPlannerView.as_view(), name="roadtrip_planner"),
    path("roadtrip/create/", CreateTripView.as_view(), name="roadtrip_create"),
    path(
        "roadtrip/<str:trip_id>/",
        TripDetailView.as_view(),
        name="roadtrip_detail",
    ),
    # Road trip HTMX endpoints
    path(
        "roadtrip/htmx/parks-along-route/",
        FindParksAlongRouteView.as_view(),
        name="roadtrip_htmx_parks_along_route",
    ),
    path(
        "roadtrip/htmx/geocode/",
        GeocodeAddressView.as_view(),
        name="roadtrip_htmx_geocode",
    ),
    path(
        "roadtrip/htmx/distance/",
        ParkDistanceCalculatorView.as_view(),
        name="roadtrip_htmx_distance",
    ),
    # Additional HTMX endpoints for client-driven route management
    path(
        "roadtrip/htmx/add-park/",
        views.htmx_add_park_to_trip,
        name="htmx_add_park_to_trip",
    ),
    path(
        "roadtrip/htmx/remove-park/",
        views.htmx_remove_park_from_trip,
        name="htmx_remove_park_from_trip",
    ),
    path(
        "roadtrip/htmx/reorder/",
        views.htmx_reorder_parks,
        name="htmx_reorder_parks",
    ),
    path(
        "roadtrip/htmx/optimize/",
        views.htmx_optimize_route,
        name="htmx_optimize_route",
    ),
    path(
        "roadtrip/htmx/calculate/",
        views.htmx_calculate_route,
        name="htmx_calculate_route",
    ),
    path(
        "roadtrip/htmx/saved/",
        views.htmx_saved_trips,
        name="htmx_saved_trips",
    ),
    path(
        "roadtrip/htmx/save/",
        views.htmx_save_trip,
        name="htmx_save_trip",
    ),
    path(
        "roadtrip/htmx/clear/",
        views.htmx_clear_trip,
        name="htmx_clear_trip",
    ),
    # Park detail and related views
    path("<slug:slug>/", views.ParkDetailView.as_view(), name="park_detail"),
    path("<slug:slug>/edit/", views.ParkUpdateView.as_view(), name="park_update"),
    path("<slug:slug>/actions/", views.park_actions, name="park_actions"),
    path("<slug:slug>/status-actions/", views.park_status_actions, name="park_status_actions"),
    path("<slug:slug>/header-badge/", views.park_header_badge, name="park_header_badge"),
    # Area views
    path(
        "<slug:park_slug>/areas/<slug:area_slug>/",
        views.ParkAreaDetailView.as_view(),
        name="area_detail",
    ),
    # Park-specific category URLs
    path(
        "<slug:park_slug>/roller-coasters/",
        ParkSingleCategoryListView.as_view(),
        {"category": "RC"},
        name="park_roller_coasters",
    ),
    path(
        "<slug:park_slug>/dark-rides/",
        ParkSingleCategoryListView.as_view(),
        {"category": "DR"},
        name="park_dark_rides",
    ),
    path(
        "<slug:park_slug>/flat-rides/",
        ParkSingleCategoryListView.as_view(),
        {"category": "FR"},
        name="park_flat_rides",
    ),
    path(
        "<slug:park_slug>/water-rides/",
        ParkSingleCategoryListView.as_view(),
        {"category": "WR"},
        name="park_water_rides",
    ),
    path(
        "<slug:park_slug>/transports/",
        ParkSingleCategoryListView.as_view(),
        {"category": "TR"},
        name="park_transports",
    ),
    path(
        "<slug:park_slug>/others/",
        ParkSingleCategoryListView.as_view(),
        {"category": "OT"},
        name="park_others",
    ),
    # Include park-specific rides URLs
    path(
        "<slug:park_slug>/rides/",
        include("apps.rides.park_urls", namespace="rides"),
    ),
    # FSM transition endpoint for parks
    # URL: /parks/<slug>/transition/<transition_name>/
    path(
        "<slug:slug>/transition/<str:transition_name>/",
        FSMTransitionView.as_view(),
        {"app_label": "parks", "model_name": "park"},
        name="park_transition",
    ),
]
