from django.urls import include, path
from rest_framework.routers import DefaultRouter

from .views import PXSourceViewSet
from . import ui_views

app_name = 'px_sources'

router = DefaultRouter()
router.register(r'api/sources', PXSourceViewSet, basename='pxsource-api')

urlpatterns = [
    # Source User Dashboard & Lists
    path('dashboard/', ui_views.source_user_dashboard, name='source_user_dashboard'),
    path('complaints/', ui_views.source_user_complaint_list, name='source_user_complaint_list'),
    path('inquiries/', ui_views.source_user_inquiry_list, name='source_user_inquiry_list'),
    path('observations/', ui_views.source_user_observation_list, name='source_user_observations'),
    path('suggestions/', ui_views.source_user_suggestion_list, name='source_user_suggestions'),
    path('communication-requests/', ui_views.source_user_communication_requests, name='source_user_communication_requests'),
    path('communication-requests/new/', ui_views.source_user_create_communication_request, name='source_user_create_communication_request'),
    
    # Source User Create (Simplified forms)
    path('complaints/new/', ui_views.source_user_create_complaint, name='source_user_create_complaint'),
    path('inquiries/new/', ui_views.source_user_create_inquiry, name='source_user_create_inquiry'),
    path('observations/new/', ui_views.source_user_create_observation, name='source_user_create_observation'),
    path('suggestions/new/', ui_views.source_user_create_suggestion, name='source_user_create_suggestion'),

    # PX Sources Management Views (Admin only)
    path('<uuid:pk>/users/create/', ui_views.source_user_create, name='source_user_create'),
    path('<uuid:pk>/users/<uuid:user_pk>/edit/', ui_views.source_user_edit, name='source_user_edit'),
    path('<uuid:pk>/users/<uuid:user_pk>/delete/', ui_views.source_user_delete, name='source_user_delete'),
    path('<uuid:pk>/users/<uuid:user_pk>/toggle/', ui_views.source_user_toggle_status, name='source_user_toggle_status'),
    path('', ui_views.source_list, name='source_list'),
    path('new/', ui_views.source_create, name='source_create'),
    path('<uuid:pk>/', ui_views.source_detail, name='source_detail'),
    path('<uuid:pk>/edit/', ui_views.source_edit, name='source_edit'),
    path('<uuid:pk>/delete/', ui_views.source_delete, name='source_delete'),
    path('<uuid:pk>/toggle/', ui_views.source_toggle_status, name='source_toggle_status'),

    # Source Complaints
    path('<uuid:pk>/source-complaints/create/', ui_views.source_complaint_create, name='source_complaint_create'),
    path('source-complaints/<uuid:pk>/convert/', ui_views.convert_to_system_complaint, name='convert_to_system_complaint'),

    # Communication Requests (Staff)
    path('communication-requests/manage/', ui_views.communication_request_list, name='communication_request_list'),
    path('communication-requests/manage/<uuid:pk>/', ui_views.communication_request_detail, name='communication_request_detail'),
    
    # AJAX Helpers
    path('ajax/search/', ui_views.ajax_search_sources, name='ajax_search_sources'),
    path('ajax/choices/', ui_views.ajax_source_choices, name='ajax_source_choices'),
    
    # API Routes
    path('', include(router.urls)),
]