from django.urls import path
from django.views.generic import RedirectView

from . import views

urlpatterns = [
    # Shop
    path('', views.shop, name='shop'),

    # Legacy /products/product/<slug>/ kept alive so shared links and anything
    # indexed keep working. These must stay above the bare <slug> routes below,
    # or "product" is swallowed as a slug. Detail redirects permanently; the
    # interest endpoint stays a live route because a redirect would drop a POST.
    path('product/<slug:slug>/',
         RedirectView.as_view(pattern_name='shop_product_detail', permanent=True)),
    path('product/<slug:slug>/interest/', views.product_show_interest),

    # Cart
    path('cart/', views.cart_view, name='shop_cart'),
    path('cart/add/<int:product_id>/', views.cart_add, name='shop_cart_add'),
    path('cart/remove/<int:product_id>/', views.cart_remove, name='shop_cart_remove'),
    path('cart/decrement/<int:product_id>/', views.cart_decrement, name='shop_cart_decrement'),

    # Checkout
    path('checkout/', views.checkout, name='shop_checkout'),
    path('order/success/', views.order_success, name='shop_order_success'),
    path('order/<str:order_number>/', views.order_detail, name='shop_order_detail'),
    path('order/<str:order_number>/pay-balance/', views.pay_balance, name='shop_pay_balance'),

    # Domain search
    path('domains/', views.domain_search, name='shop_domain_search'),
    path('domains/add-to-cart/', views.domain_add_to_cart, name='shop_domain_add_to_cart'),

    # Stripe webhook
    path('webhook/stripe/', views.stripe_webhook, name='shop_stripe_webhook'),

    # Email previews (dev only)
    path('email-preview/<str:template>/', views.email_preview, name='shop_email_preview'),

    # Canonical product address: /products/<slug>/
    path('<slug:slug>/', views.product_detail, name='shop_product_detail'),
    path('<slug:slug>/interest/', views.product_show_interest, name='shop_product_interest'),
]
