from django.urls import path, include
from . import views
from .teacher_fee_views import TeacherClassFeeDuesView
from master_admin.language_views import MySchoolLanguagesView, TranslateView

urlpatterns = [
    # =====================================================
    # AUTHENTICATION ENDPOINTS
    # =====================================================
    path("login/", views.TeacherLoginView.as_view(), name="teacher-login"),
    path(
        "verify-otp/", views.VerifyTeacherOTPView.as_view(), name="teacher-verify-otp"
    ),
    path("logout/", views.TeacherLogoutView.as_view(), name="teacher-logout"),
    # =====================================================
    # LANGUAGES
    # =====================================================
    path("languages/", MySchoolLanguagesView.as_view(), name="teacher-languages"),
    path("translate/", TranslateView.as_view(), name="teacher-translate"),
    # =====================================================
    # TEACHER PROFILE AND DETAILS
    # =====================================================
    path("profile/", views.TeacherProfileView.as_view(), name="teacher-profile"),
    path("detail/", views.TeacherDetailView.as_view(), name="teacher-detail"),
    path(
        "academic-years/",
        views.TeacherAcademicYearsView.as_view(),
        name="teacher-academic-years",
    ),
    path(
        "today-schedule/",
        views.TeacherTodayScheduleView.as_view(),
        name="today-schedule",
    ),
    path(
        "teacher-class-students/",
        views.TeacherClassStudentsView.as_view(),
        name="teacher-class-students",
    ),
    path(
        "student-detail/<int:enrollment_id>/",
        views.TeacherStudentDetailView.as_view(),
        name="teacher-student-detail",
    ),
    # Fee dues for class teacher's class (component-wise + bus fee, for reminders)
    path(
        "fee-dues/",
        TeacherClassFeeDuesView.as_view(),
        name="teacher-fee-dues",
    ),
    # =====================================================
    # TASK MANAGEMENT API
    # =====================================================
    # Task Types (read-only dropdown)
    path("task-types/", views.TaskTypeListView.as_view(), name="task-type-list"),
    path("my-classes/", views.TeacherClassesView.as_view(), name="teacher-classes"),
    path("my-subjects/", views.TeacherSubjectsView.as_view(), name="teacher-subjects"),
    # ── Class Tasks ──────────────────────────────────────────────────
    path("tasks/", views.ClassTaskListCreateView.as_view(), name="task-list-create"),
    path(
        "ai/generate-questions/",
        views.AIGenerateQuestionsView.as_view(),
        name="ai-generate-questions",
    ),
    path(
        "ai/generate-questions-batch/",
        views.AIGenerateQuestionsBatchView.as_view(),
        name="ai-generate-questions-batch",
    ),
    path(
        "tasks/<int:task_id>/", views.ClassTaskDetailView.as_view(), name="task-detail"
    ),
    path(
        "tasks/<int:task_id>/publish/",
        views.TaskPublishView.as_view(),
        name="task-publish",
    ),
    path("my-tasks/", views.MyTasksView.as_view(), name="my-tasks"),
    # ── Task Items ───────────────────────────────────────────────────
    path(
        "tasks/<int:task_id>/items/",
        views.TaskItemListCreateView.as_view(),
        name="task-item-list-create",
    ),
    path(
        "task-items/<int:item_id>/",
        views.TaskItemDetailView.as_view(),
        name="task-item-detail",
    ),
    # ── Class Task Submissions (teacher reviews) ─────────────────────
    path(
        "tasks/<int:task_id>/submissions/",
        views.ClassTaskSubmissionsView.as_view(),
        name="task-submissions",
    ),
    path(
        "submissions/<int:submission_id>/",
        views.SubmissionDetailView.as_view(),
        name="submission-detail",
    ),
    path(
        "submissions/<int:submission_id>/grade/",
        views.GradeSubmissionView.as_view(),
        name="grade-submission",
    ),
    # ── Specific Student Tasks ───────────────────────────────────────
    path(
        "classes/<int:class_id>/students/",
        views.ClassStudentsForTaskView.as_view(),
        name="class-students-for-task",
    ),
    path(
        "specific-tasks/",
        views.SpecificStudentTaskListCreateView.as_view(),
        name="specific-task-list-create",
    ),
    path(
        "specific-tasks/<int:task_id>/",
        views.SpecificStudentTaskDetailView.as_view(),
        name="specific-task-detail",
    ),
    path(
        "specific-tasks/<int:task_id>/assignments/",
        views.SpecificTaskAssignmentsView.as_view(),
        name="specific-task-assignments",
    ),
    path(
        "specific-assignments/<int:assignment_id>/answers/",
        views.SpecificStudentTaskAnswerView.as_view(),
        name="specific-task-answers",
    ),
    path(
        "specific-assignments/<int:assignment_id>/grade/",
        views.SpecificStudentTaskAnswerView.as_view(),
        name="specific-task-grade",
    ),
    path(
        "attendance/today/status/",
        views.TodayAttendanceStatusView.as_view(),
        name="today-attendance-status",
    ),
    # Start/Mark attendance session
    path(
        "attendance/start/",
        views.StartAttendanceView.as_view(),
        name="start-attendance",
    ),
    # Get attendance session details
    path(
        "attendance/session/<int:session_id>/",
        views.AttendanceSessionDetailView.as_view(),
        name="attendance-session-detail",
    ),
    # Mark student attendance
    path(
        "attendance/session/<int:session_id>/mark/",
        views.MarkStudentAttendanceView.as_view(),
        name="mark-student-attendance",
    ),
    # Bulk mark attendance
    path(
        "attendance/session/<int:session_id>/bulk-mark/",
        views.BulkMarkAttendanceView.as_view(),
        name="bulk-mark-attendance",
    ),
    # Submit attendance session
    path(
        "attendance/session/<int:session_id>/submit/",
        views.SubmitAttendanceView.as_view(),
        name="submit-attendance",
    ),
    # Get attendance history
    path(
        "attendance/history/",
        views.AttendanceHistoryView.as_view(),
        name="attendance-history",
    ),
    # Get attendance summary
    path(
        "attendance/summary/",
        views.AttendanceSummaryView.as_view(),
        name="attendance-summary",
    ),
    # Get attendance reports
    path(
        "attendance/reports/",
        views.AttendanceReportsView.as_view(),
        name="attendance-reports",
    ),
    # =====================================================
    # TEACHER CHAT ROUTES
    # =====================================================
    # Get classes for chat (with existing group info)
    path(
        "chat/classes/",
        views.TeacherClassesForChatView.as_view(),
        name="teacher-chat-classes",
    ),
    # Get students (with parent details) for direct-message chat creation
    path(
        "chat/class-students/",
        views.TeacherClassStudentsForChatView.as_view(),
        name="teacher-chat-class-students",
    ),
    # Create or retrieve a 1-to-1 chat with a student or parent
    path(
        "chat/create-direct/",
        views.TeacherCreateDirectChatView.as_view(),
        name="teacher-chat-create-direct",
    ),
    # Create or get class group
    path(
        "chat/create-class-group/",
        views.TeacherCreateClassGroupView.as_view(),
        name="teacher-create-class-group",
    ),
    # Create or get subject group
    path(
        "chat/create-subject-group/",
        views.TeacherCreateSubjectGroupView.as_view(),
        name="teacher-create-subject-group",
    ),
    # Get all chat rooms for teacher
    path(
        "chat/rooms/",
        views.TeacherChatRoomListView.as_view(),
        name="teacher-chat-rooms",
    ),
    # Get messages for a specific chat room
    path(
        "chat/rooms/<uuid:room_id>/messages/",
        views.TeacherChatMessageListView.as_view(),
        name="teacher-chat-messages",
    ),
    # Mark all messages as read in a room
    path(
        "chat/rooms/<uuid:room_id>/mark-read/",
        views.TeacherChatMarkAsReadView.as_view(),
        name="teacher-chat-mark-read",
    ),
    # Get total unread count across all rooms
    path(
        "chat/unread-count/",
        views.TeacherChatUnreadCountView.as_view(),
        name="teacher-chat-unread-count",
    ),
    # Get participants for a specific chat room
    path(
        "chat/rooms/<uuid:room_id>/participants/",
        views.TeacherChatRoomParticipantsView.as_view(),
        name="teacher-chat-room-participants",
    ),
    # Delete a class/subject group (teacher must be ADMIN in that room)
    path(
        "chat/rooms/<uuid:room_id>/",
        views.TeacherDeleteGroupView.as_view(),
        name="teacher-delete-group",
    ),
    # Make a participant admin in a chat room
    path(
        "chat/rooms/<uuid:room_id>/make-admin/",
        views.TeacherMakeRoomAdminView.as_view(),
        name="teacher-chat-make-admin",
    ),
    # Remove admin privileges from a participant
    path(
        "chat/rooms/<uuid:room_id>/remove-admin/",
        views.TeacherRemoveRoomAdminView.as_view(),
        name="teacher-chat-remove-admin",
    ),
    path(
        "leaves/types/",
        views.TeacherLeaveTypesView.as_view(),
        name="teacher-leaves-types",
    ),
    path(
        "leaves/pending/",
        views.TeacherPendingLeaveRequestsView.as_view(),
        name="teacher-leaves-pending",
    ),
    # Get all leave requests with filters
    path(
        "leaves/",
        views.TeacherAllLeaveRequestsView.as_view(),
        name="teacher-leaves-all",
    ),
    # Get leave statistics
    path(
        "leaves/statistics/",
        views.TeacherLeaveStatisticsView.as_view(),
        name="teacher-leaves-statistics",
    ),
    # Bulk action on multiple leave requests
    path(
        "leaves/bulk-action/",
        views.TeacherBulkLeaveActionView.as_view(),
        name="teacher-leaves-bulk",
    ),
    # Get specific leave request details
    path(
        "leaves/<int:leave_id>/",
        views.TeacherLeaveRequestDetailView.as_view(),
        name="teacher-leaves-detail",
    ),
    # Approve a leave request
    path(
        "leaves/<int:leave_id>/approve/",
        views.TeacherApproveLeaveView.as_view(),
        name="teacher-leaves-approve",
    ),
    # Reject a leave request
    path(
        "leaves/<int:leave_id>/reject/",
        views.TeacherRejectLeaveView.as_view(),
        name="teacher-leaves-reject",
    ),
    # Add these to your teacher/urls.py
    # =====================================================
    # TEACHER MARKS MANAGEMENT API
    # =====================================================
    # Get subjects and standards (first step - dropdown)
    path(
        "marks/subjects-standards/",
        views.TeacherSubjectsStandardsView.as_view(),
        name="teacher-marks-subjects-standards",
    ),
    # Get exams for a specific class and subject with pagination
    path(
        "marks/class-exams/",
        views.TeacherClassExamsView.as_view(),
        name="teacher-marks-class-exams",
    ),
    # Get all subjects with classes for marks entry
    path(
        "marks/subjects/",
        views.TeacherSubjectsWithClassesView.as_view(),
        name="teacher-marks-subjects",
    ),
    # Get students for a specific class and subject with pagination
    path(
        "marks/class-students/",
        views.TeacherClassStudentsForMarksView.as_view(),
        name="teacher-marks-class-students",
    ),
    # Enter marks for a single student
    path(
        "marks/enter/",
        views.TeacherEnterStudentMarksView.as_view(),
        name="teacher-marks-enter",
    ),
    # Bulk marks entry for multiple students
    path(
        "marks/bulk-entry/",
        views.TeacherBulkMarksEntryView.as_view(),
        name="teacher-marks-bulk-entry",
    ),
    # Get marks summary for a subject
    path(
        "marks/subject-summary/",
        views.TeacherSubjectMarksSummaryView.as_view(),
        name="teacher-marks-subject-summary",
    ),
    # Submit/finalize marks for a subject
    path(
        "marks/submit/",
        views.TeacherSubmitMarksView.as_view(),
        name="teacher-marks-submit",
    ),
    # Get all pending marks entries
    path(
        "marks/pending/",
        views.TeacherPendingMarksView.as_view(),
        name="teacher-marks-pending",
    ),
    # Get exam subjects for marks entry
    path(
        "marks/exam-subjects/",
        views.TeacherExamSubjectsForMarksView.as_view(),
        name="teacher-marks-exam-subjects",
    ),
    # Add these to your teacher/urls.py urlpatterns
    # =====================================================
    # TEACHER PAYSLIP MANAGEMENT API
    # =====================================================
    # Get all pay slips for logged-in teacher
    path(
        "payslips/",
        views.TeacherMyPaySlipsView.as_view(),
        name="teacher-payslips",
    ),
    # Get pay slip summary statistics
    path(
        "payslips/summary/",
        views.TeacherPaySlipSummaryView.as_view(),
        name="teacher-payslips-summary",
    ),
    # Get current pay structure
    path(
        "payslips/current-pay-structure/",
        views.TeacherCurrentPayStructureView.as_view(),
        name="teacher-current-pay-structure",
    ),
    # Get specific pay slip details
    path(
        "payslips/<int:pay_slip_id>/",
        views.TeacherPaySlipDetailView.as_view(),
        name="teacher-payslip-detail",
    ),
    # Acknowledge pay slip
    path(
        "payslips/<int:pay_slip_id>/acknowledge/",
        views.TeacherAcknowledgePaySlipView.as_view(),
        name="teacher-payslip-acknowledge",
    ),
    # Download pay slip (for PDF generation)
    path(
        "payslips/<int:pay_slip_id>/download/",
        views.TeacherDownloadPaySlipView.as_view(),
        name="teacher-payslip-download",
    ),
    # =====================================================
    # STUDY MATERIALS
    # =====================================================
    path(
        "study-materials/",
        views.StudyMaterialListCreateView.as_view(),
        name="study-material-list-create",
    ),
    path(
        "study-materials/<int:pk>/",
        views.StudyMaterialDetailView.as_view(),
        name="study-material-detail",
    ),
    path(
        "study-materials/<int:pk>/download/",
        views.StudyMaterialDownloadView.as_view(),
        name="study-material-download",
    ),
    # =====================================================
    # PREVIOUS YEAR PAPERS
    # =====================================================
    path(
        "previous-year-papers/",
        views.PreviousYearPaperListCreateView.as_view(),
        name="pyq-list-create",
    ),
    path(
        "previous-year-papers/<int:pk>/",
        views.PreviousYearPaperDetailView.as_view(),
        name="pyq-detail",
    ),
    path(
        "previous-year-papers/<int:pk>/download/",
        views.PreviousYearPaperDownloadView.as_view(),
        name="pyq-download",
    ),
    # Subjects + standards available to teacher (for upload dropdowns)
    path(
        "materials/my-subjects/",
        views.TeacherSubjectsForMaterialsView.as_view(),
        name="materials-my-subjects",
    ),
    # =====================================================
    # STUDENT ANNOUNCEMENTS (teacher-initiated)
    # =====================================================
    path(
        "announcements/types/",
        views.TeacherAnnouncementTypesView.as_view(),
        name="teacher-announcement-types",
    ),
    path(
        "announcements/student/",
        views.TeacherStudentAnnouncementListCreateView.as_view(),
        name="teacher-student-announcement-list-create",
    ),
    path(
        "announcements/student/<int:pk>/",
        views.TeacherStudentAnnouncementDetailView.as_view(),
        name="teacher-student-announcement-detail",
    ),
    # =====================================================
    # CLASS TESTS (Mini / Daily Tests — teacher-initiated)
    # =====================================================
    # Available timetable periods for a given date (used when creating a test)
    path(
        "class-tests/available-periods/",
        views.TeacherAvailablePeriodsView.as_view(),
        name="class-test-available-periods",
    ),
    # List teacher's tests / create a new test
    path(
        "class-tests/",
        views.TeacherClassTestListCreateView.as_view(),
        name="class-test-list-create",
    ),
    # Test detail / edit / delete
    path(
        "class-tests/<int:test_id>/",
        views.TeacherClassTestDetailView.as_view(),
        name="class-test-detail",
    ),
    # Students with their marks for a test
    path(
        "class-tests/<int:test_id>/students/",
        views.TeacherClassTestStudentsView.as_view(),
        name="class-test-students",
    ),
    # Bulk marks entry
    path(
        "class-tests/<int:test_id>/marks/",
        views.TeacherClassTestBulkMarksView.as_view(),
        name="class-test-marks",
    ),
    # Test summary / analytics
    path(
        "class-tests/<int:test_id>/summary/",
        views.TeacherClassTestSummaryView.as_view(),
        name="class-test-summary",
    ),
    # =====================================================
    # TEACHER ACTIVITY LOG
    # =====================================================
    path("", include("activities.urls")),
]
