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

from .views import (
    PublicSurveyViewSet,
    SurveyInstanceViewSet,
    SurveyQuestionViewSet,
    SurveyResponseViewSet,
    SurveyTemplateViewSet,
)
from . import public_views, ui_views

app_name = 'surveys'

router = DefaultRouter()
router.register(r'api/templates', SurveyTemplateViewSet, basename='survey-template-api')
router.register(r'api/questions', SurveyQuestionViewSet, basename='survey-question-api')
router.register(r'api/instances', SurveyInstanceViewSet, basename='survey-instance-api')
router.register(r'api/responses', SurveyResponseViewSet, basename='survey-response-api')

urlpatterns = [
    # Public survey pages (no auth required)
    path('s/<str:token>/', public_views.survey_form, name='survey_form'),
    path('s/<str:token>/thank-you/', public_views.thank_you, name='thank_you'),
    path('invalid/', public_views.invalid_token, name='invalid_token'),
    
    # UI Views (authenticated)
    path('instances/', ui_views.survey_instance_list, name='instance_list'),
    path('instances/<uuid:pk>/', ui_views.survey_instance_detail, name='instance_detail'),
    path('instances/<uuid:pk>/log-contact/', ui_views.survey_log_patient_contact, name='log_patient_contact'),
    path('instances/<uuid:pk>/send-satisfaction/', ui_views.survey_send_satisfaction_feedback, name='send_satisfaction_feedback'),
    path('templates/', ui_views.survey_template_list, name='template_list'),
    
    # Public API endpoints (no auth required)
    path('public/<str:token>/', PublicSurveyViewSet.as_view({'get': 'retrieve'}), name='public-survey'),
    path('public/<str:token>/submit/', PublicSurveyViewSet.as_view({'post': 'submit'}), name='public-survey-submit'),
    
    # Authenticated API endpoints
    path('', include(router.urls)),
]
