from django.urls import path, include

from generic.urls import generic_exam_urls, generic_view_urls
from . import views

app_name = "physics"

urlpatterns = []

urlpatterns.extend(
    [
        path("question/", views.QuestionView.as_view(), name="question_view"),
        path("question/create/", views.QuestionCreate.as_view(), name="question_create"),
        path("question/create/exam/<int:pk>", views.QuestionCreate.as_view(), name="question_create_exam"),
        path("question/<int:pk>/", views.question_detail, name="question_detail"),
        path("exam/<int:pk>/take_old", views.exam_take_old, name="exam_take_old"),
        path(
            "exam/<int:pk>/<int:sk>/<str:cid>/<str:passcode>/take",
            views.exam_take,
            name="exam_take",
        ),
        path(
            "exam/<int:pk>/<int:sk>/take",
            views.exam_take,
            name="exam_take_user",
        ),
        # HTMX fragment endpoint for loading the question+controls via AJAX
        path(
            "exam/<int:pk>/<int:sk>/fragment",
            views.exam_take_fragment,
            name="exam_take_fragment_user",
        ),
        path(
            "exam/<int:pk>/<int:sk>/<str:cid>/<str:passcode>/fragment",
            views.exam_take_fragment,
            name="exam_take_fragment",
        ),
        # Flag toggle (HTMX)
        path(
            "exam/<int:pk>/<int:sk>/toggle_flag",
            views.exam_toggle_flag,
            name="exam_toggle_flag_user",
        ),
        path(
            "exam/<int:pk>/<int:sk>/<str:cid>/<str:passcode>/toggle_flag",
            views.exam_toggle_flag,
            name="exam_toggle_flag",
        ),
        path("exam/<int:pk>/start", views.exam_start, name="exam_start"),
        path(
            "exam/<int:pk>/<str:cid>/<str:passcode>/finish",
            views.exam_take_overview,
            name="exam_take_overview",
        ),
        path(
            "exam/<int:pk>/finish",
            views.exam_take_overview,
            name="exam_take_overview_user",
        ),
        path(
            "exam/<int:pk>/<str:cid>/<str:passcode>/complete",
            views.exam_complete,
            name="exam_complete",
        ),
        path(
            "exam/<int:pk>/complete",
            views.exam_complete,
            name="exam_complete_user",
        ),
        path("exam/<int:pk>/markers", views.ExamMarkersUpdate.as_view(), name="exam_markers"),
        path("exam/<int:pk>/groups", views.ExamGroupsUpdate.as_view(), name="exam_groups_edit"),
        path(
            "exam/<int:pk>/authors",
            views.ExamAuthorUpdate.as_view(),
            name="exam_authors",
        ),
        path("exam/<int:exam_id>/clone", views.ExamClone.as_view(), name="exam_clone"),
        path("exam/<int:pk>/update", views.ExamUpdate.as_view(), name="exam_update"),
        path("exam/<int:pk>/delete", views.ExamDelete.as_view(), name="exam_delete"),
        path("exam/available", views.active_exams, name="active_exams"),
        # path("exam/json/<int:pk>", views.exam_json, name="exam_json"),
        # path("exam/json/<int:pk>/recreate", views.exam_json_recreate, name="exam_json_recreate"),
        path(
            "user_answers/",
            views.UserAnswerTableView.as_view(),
            name="user_answer_table_view",
        ),
        path(
            "user_answers/<int:pk>",
            views.UserAnswerView.as_view(),
            name="user_answer_view",
        ),
        path(
            "user_answers/<int:pk>/delete",
            views.UserAnswerDelete.as_view(),
            name="user_answer_delete",
        ),
        path(
            "exam/<int:pk>/review/<int:q_index>/responses",
            views.exam_review_question_responses,
            name="exam_review_question_responses",
        ),
        path(
            "exam/<int:pk>/review/<int:q_index>/summary",
            views.exam_review_question_summary,
            name="exam_review_question_summary",
        ),
        # TODO: consider merging with generic...
        #path(
        #    "exam/<int:pk>/scores/<int:cid>/<str:passcode>/",
        #    views.exam_scores_cid_user,
        #    name="exam_scores_cid_user",
        #),
        #path(
        #    "exam/<int:pk>/scores/",
        #    views.exam_scores_cid_user,
        #    name="exam_scores_user",
        #),
    ]
)

urlpatterns.extend(generic_view_urls(views.GenericViews))
urlpatterns.extend(generic_exam_urls(views.GenericExamViews))