from django.contrib.auth import views as auth_views
from django.urls import path

from core import views

app_name = "core"

urlpatterns = [
    # Public / discovery
    path("", views.home, name="home"),
    path("search/", views.listing_search, name="listing_search"),
    path("category/<slug:slug>/", views.category_browse, name="category_browse"),
    path("category/<int:category_id>/fields.json", views.category_fields_json, name="category_fields_json"),
    path("listings/new/", views.listing_create, name="listing_create"),
    path("listings/<slug:slug>/", views.listing_detail, name="listing_detail"),
    path("listings/<slug:slug>/contact-click/", views.register_contact_click, name="register_contact_click"),
    
    
    # Auth
    path("accounts/signup/", views.signup, name="signup"),
    path("accounts/login/", views.AccoLoginView.as_view(), name="login"),
    path("accounts/logout/", views.logout_view, name="logout"),
    
    # Password reset (using Django's built-in views)
    path(
        "accounts/password-reset/",
        auth_views.PasswordResetView.as_view(
            template_name="core/auth/password_reset.html",
            email_template_name="core/auth/password_reset_email.html",
            subject_template_name="core/auth/password_reset_subject.txt"
        ),
        name="password_reset",
    ),
    path(
        "accounts/password-reset/done/",
        auth_views.PasswordResetDoneView.as_view(
            template_name="core/auth/password_reset_done.html"
        ),
        name="password_reset_done",
    ),
    path(
        "accounts/reset/<uidb64>/<token>/",
        auth_views.PasswordResetConfirmView.as_view(
            template_name="core/auth/password_reset_confirm.html"
        ),
        name="password_reset_confirm",
    ),
    path(
        "accounts/reset/done/",
        auth_views.PasswordResetCompleteView.as_view(
            template_name="core/auth/password_reset_complete.html"
        ),
        name="password_reset_complete",
    ),
    

    # Profile & KYC
    path("profile/", views.profile_view, name="profile_view"),
    path("profile/edit/", views.profile_edit, name="profile_edit"),
    path("profile/<str:username>/", views.profile_view, name="profile_view_by_username"),
    path("become-lister/", views.become_lister, name="become_lister"),
    path("kyc/submit/", views.kyc_submit, name="kyc_submit"),

    # Dashboard & listing CRUD
    path("dashboard/", views.dashboard, name="dashboard"),
    path("listings/<slug:slug>/edit/", views.listing_edit, name="listing_edit"),
    path("listings/<slug:slug>/delete/", views.listing_delete, name="listing_delete"),
    path("listings/<slug:slug>/status/", views.listing_status_update, name="listing_status_update"),
    path("listing-photos/<int:photo_id>/delete/", views.listing_photo_delete, name="listing_photo_delete"),

    # Favorites & saved searches
    path("listings/<slug:slug>/favorite/", views.toggle_favorite, name="toggle_favorite"),
    path("favorites/", views.favorites_list, name="favorites_list"),
    path("saved-searches/", views.saved_search_list, name="saved_search_list"),
    path("saved-searches/<int:pk>/delete/", views.saved_search_delete, name="saved_search_delete"),

    # Reviews
    path("listings/<slug:slug>/review/", views.review_create, name="review_create"),
    path("reviews/<int:pk>/flag/", views.review_flag, name="review_flag"),
    path("reviews/<int:pk>/reply/", views.review_reply, name="review_reply"),

    # Inquiries
    path("listings/<slug:slug>/inquire/", views.inquiry_create, name="inquiry_create"),

    # Messaging
    path("messages/", views.conversation_list, name="conversation_list"),
    path("messages/<int:pk>/", views.conversation_detail, name="conversation_detail"),
    path("listings/<slug:slug>/message/", views.conversation_start, name="conversation_start"),

    # Notifications
    path("notifications/", views.notification_list, name="notification_list"),

    # Trust & safety
    path("report/listing/<slug:slug>/", views.report_create, name="report_listing"),
    path("report/user/<str:username>/", views.report_create, name="report_user"),

    # Intent
    path("set-intent/", views.set_intent, name="set_intent"),

    # -------------------------------------------------------------------
    # Events — dedicated content type (own discovery page, CRUD, tickets)
    # Static paths must be declared before the <slug:slug> catch-all.
    # -------------------------------------------------------------------
    path("events/", views.event_list, name="event_list"),
    path("events/new/", views.event_create, name="event_create"),
    path("events/mine/", views.my_events, name="my_events"),
    path("events/tickets/", views.my_tickets, name="my_tickets"),
    path("events/saved/", views.event_favorites_list, name="event_favorites_list"),
    path("events/<slug:slug>/", views.event_detail, name="event_detail"),
    path("events/<slug:slug>/edit/", views.event_edit, name="event_edit"),
    path("events/<slug:slug>/delete/", views.event_delete, name="event_delete"),
    path("events/<slug:slug>/status/", views.event_status_update, name="event_status_update"),
    path("events/<slug:slug>/favorite/", views.toggle_event_favorite, name="toggle_event_favorite"),
    path("events/<slug:slug>/book/", views.event_book_tickets, name="event_book_tickets"),
    path("event-photos/<int:photo_id>/delete/", views.event_photo_delete, name="event_photo_delete"),
    path("event-tickets/<int:order_id>/cancel/", views.event_ticket_cancel, name="event_ticket_cancel"),
    path("report/event/<slug:event_slug>/", views.report_create, name="report_event"),
]