from django.urls import path
from . import views_frontend
from . import views
from . import views_integration
from . import views_source

urlpatterns = [
    path("", views_frontend.dashboard_view, name="dashboard"),
    # Job URLs (using JobPosting model)
    path("persons/", views.PersonListView.as_view(), name="person_list"),
    path("persons/create/", views.PersonCreateView.as_view(), name="person_create"),
    path("persons/<slug:slug>/", views.PersonDetailView.as_view(), name="person_detail"),
    path("persons/<slug:slug>/update/", views.PersonUpdateView.as_view(), name="person_update"),
    path("persons/<slug:slug>/delete/", views.PersonDeleteView.as_view(), name="person_delete"),

    path("jobs/", views_frontend.JobListView.as_view(), name="job_list"),
    path("jobs/create/", views.create_job, name="job_create"),
    path(
        "job/<slug:slug>/upload_image_simple/",
        views.job_image_upload,
        name="job_image_upload",
    ),
    path("jobs/<slug:slug>/update/", views.edit_job, name="job_update"),
    # path('jobs/<slug:slug>/delete/', views., name='job_delete'),
    path('jobs/<slug:slug>/', views.job_detail, name='job_detail'),
    # path('jobs/<slug:slug>/download/cvs/', views.job_cvs_download, name='job_cvs_download'),
    path('job/<slug:slug>/request-download/', views.request_cvs_download, name='request_cvs_download'),
    path('job/<slug:slug>/download-ready/', views.download_ready_cvs, name='download_ready_cvs'),

    path('careers/',views.kaauh_career,name='kaauh_career'),

    # LinkedIn Integration URLs
    path(
        "jobs/<slug:slug>/post-to-linkedin/",
        views.post_to_linkedin,
        name="post_to_linkedin",
    ),
    path("jobs/linkedin/login/", views.linkedin_login, name="linkedin_login"),
    path("jobs/linkedin/callback/", views.linkedin_callback, name="linkedin_callback"),
    path("jobs/<slug:slug>/staff-assignment/", views.staff_assignment_view, name="staff_assignment_view"),

    # Candidate URLs
    path(
        "candidates/", views_frontend.ApplicationListView.as_view(), name="candidate_list"
    ),
    path(
        "candidates/create/",
        views_frontend.ApplicationCreateView.as_view(),
        name="candidate_create",
    ),
    path(
        "candidates/create/<slug:slug>/",
        views_frontend.ApplicationCreateView.as_view(),
        name="candidate_create_for_job",
    ),
    path(
        "jobs/<slug:slug>/candidates/",
        views_frontend.JobApplicationListView.as_view(),
        name="job_candidates_list",
    ),
    path(
        "candidates/<slug:slug>/update/",
        views_frontend.ApplicationUpdateView.as_view(),
        name="candidate_update",
    ),
    path(
        "candidates/<slug:slug>/delete/",
        views_frontend.ApplicationDeleteView.as_view(),
        name="candidate_delete",
    ),
    path(
        "candidate/<slug:slug>/view/",
        views_frontend.candidate_detail,
        name="candidate_detail",
    ),
    path(
        "candidate/<slug:slug>/resume-template/",
        views_frontend.candidate_resume_template_view,
        name="candidate_resume_template",
    ),
    path(
        "candidate/<slug:slug>/update-stage/",
        views_frontend.candidate_update_stage,
        name="candidate_update_stage",
    ),
    path(
        "candidate/<slug:slug>/retry-scoring/",
        views_frontend.retry_scoring_view,
        name="candidate_retry_scoring",
    ),
    # Training URLs
    path("training/", views_frontend.TrainingListView.as_view(), name="training_list"),
    path(
        "training/create/",
        views_frontend.TrainingCreateView.as_view(),
        name="training_create",
    ),
    path(
        "training/<slug:slug>/",
        views_frontend.TrainingDetailView.as_view(),
        name="training_detail",
    ),
    path(
        "training/<slug:slug>/update/",
        views_frontend.TrainingUpdateView.as_view(),
        name="training_update",
    ),
    path(
        "training/<slug:slug>/delete/",
        views_frontend.TrainingDeleteView.as_view(),
        name="training_delete",
    ),
    # Meeting URLs
    # path("meetings/", views.ZoomMeetingListView.as_view(), name="list_meetings"),

    # JobPosting functional views URLs (keeping for compatibility)
    path("api/create/", views.create_job, name="create_job_api"),
    path("api/<slug:slug>/edit/", views.edit_job, name="edit_job_api"),
    # ERP Integration URLs
    path(
        "integration/erp/",
        views_integration.ERPIntegrationView.as_view(),
        name="erp_integration",
    ),
    path(
        "integration/erp/create-job/",
        views_integration.erp_create_job_view,
        name="erp_create_job",
    ),
    path(
        "integration/erp/update-job/",
        views_integration.erp_update_job_view,
        name="erp_update_job",
    ),
    path(
        "integration/erp/health/",
        views_integration.erp_integration_health,
        name="erp_integration_health",
    ),
    # Form Preview URLs
    # path('forms/', views.form_list, name='form_list'),
    path("forms/builder/", views.form_builder, name="form_builder"),
    path(
        "forms/builder/<slug:template_slug>/", views.form_builder, name="form_builder"
    ),
    path("forms/", views.form_templates_list, name="form_templates_list"),
    path(
        "forms/create-template/",
        views.create_form_template,
        name="create_form_template",
    ),
    path(
        "jobs/<slug:slug>/edit_linkedin_post_content/",
        views.edit_linkedin_post_content,
        name="edit_linkedin_post_content",
    ),
    path(
        "jobs/<slug:slug>/candidate_screening_view/",
        views.candidate_screening_view,
        name="candidate_screening_view",
    ),
    path(
        "jobs/<slug:slug>/candidate_exam_view/",
        views.candidate_exam_view,
        name="candidate_exam_view",
    ),
    path(
        "jobs/<slug:slug>/candidate_interview_view/",
        views.candidate_interview_view,
        name="candidate_interview_view",
    ),
    path(
        "jobs/<slug:slug>/candidate_document_review_view/",
        views.candidate_document_review_view,
        name="candidate_document_review_view",
    ),
    path(
        "jobs/<slug:slug>/candidate_offer_view/",
        views_frontend.candidate_offer_view,
        name="candidate_offer_view",
    ),
    path(
        "jobs/<slug:slug>/candidate_hired_view/",
        views_frontend.candidate_hired_view,
        name="candidate_hired_view",
    ),
    path(
        "jobs/<slug:job_slug>/export/<str:stage>/csv/",
        views_frontend.export_candidates_csv,
        name="export_candidates_csv",
    ),
    path(
        "jobs/<slug:job_slug>/candidates/<slug:candidate_slug>/update_status/<str:stage_type>/<str:status>/",
        views_frontend.update_candidate_status,
        name="update_candidate_status",
    ),
    # Sync URLs
    path(
        "jobs/<slug:job_slug>/sync-hired-candidates/",
        views_frontend.sync_hired_candidates,
        name="sync_hired_candidates",
    ),
    path(
        "sources/<int:source_id>/test-connection/",
        views_frontend.test_source_connection,
        name="test_source_connection",
    ),
    path(
        "jobs/<slug:slug>/<int:candidate_id>/reschedule_meeting_for_candidate/<int:meeting_id>/",
        views.reschedule_meeting_for_candidate,
        name="reschedule_meeting_for_candidate",
    ),
    path(
        "jobs/<slug:slug>/update_candidate_exam_status/",
        views.update_candidate_exam_status,
        name="update_candidate_exam_status",
    ),
    path(
        "jobs/<slug:slug>/bulk_update_candidate_exam_status/",
        views.bulk_update_candidate_exam_status,
        name="bulk_update_candidate_exam_status",
    ),
    path(
        "htmx/<int:pk>/candidate_criteria_view/",
        views.candidate_criteria_view_htmx,
        name="candidate_criteria_view_htmx",
    ),
    path(
        "htmx/<slug:slug>/candidate_set_exam_date/",
        views.candidate_set_exam_date,
        name="candidate_set_exam_date",
    ),
    path(
        "htmx/<slug:slug>/candidate_update_status/",
        views.candidate_update_status,
        name="candidate_update_status",
    ),
    # path('forms/form/<slug:template_slug>/submit/', views.submit_form, name='submit_form'),
    # path('forms/form/<slug:template_slug>/', views.form_wizard_view, name='form_wizard'),
    path(
        "forms/<int:template_id>/submissions/<slug:slug>/",
        views.form_submission_details,
        name="form_submission_details",
    ),
    path(
        "forms/template/<slug:slug>/submissions/",
        views.form_template_submissions_list,
        name="form_template_submissions_list",
    ),
    path(
        "forms/template/<int:template_id>/all-submissions/",
        views.form_template_all_submissions,
        name="form_template_all_submissions",
    ),
    # path('forms/<int:form_id>/', views.form_preview, name='form_preview'),
    # path('forms/<int:form_id>/submit/', views.form_submit, name='form_submit'),
    # path('forms/<int:form_id>/embed/', views.form_embed, name='form_embed'),
    # path('forms/<int:form_id>/submissions/', views.form_submissions, name='form_submissions'),
    # path('forms/<int:form_id>/edit/', views.edit_form, name='edit_form'),
    # path('api/forms/save/', views.save_form_builder, name='save_form_builder'),
    # path('api/forms/<int:form_id>/load/', views.load_form, name='load_form'),
    # path('api/forms/<int:form_id>/update/', views.update_form_builder, name='update_form_builder'),
    # path('api/templates/', views.list_form_templates, name='list_form_templates'),
    # path('api/templates/save/', views.save_form_template, name='save_form_template'),
    # path('api/templates/<slug:template_slug>/', views.load_form_template, name='load_form_template'),
    # path('api/templates/<slug:template_slug>/delete/', views.delete_form_template, name='delete_form_template'),
    path(
        "jobs/<slug:slug>/calendar/",
        views.interview_calendar_view,
        name="interview_calendar",
    ),
    path(
        "jobs/<slug:slug>/calendar/interview/<int:interview_id>/",
        views.interview_detail_view,
        name="interview_detail",
    ),

    # users urls
    path("user/<int:pk>", views.user_detail, name="user_detail"),
    path(
        "user/user_profile_image_update/<int:pk>",
        views.user_profile_image_update,
        name="user_profile_image_update",
    ),
    path("easy_logs/", views.easy_logs, name="easy_logs"),
    path("settings/", views.admin_settings, name="admin_settings"),
    path("staff/create", views.create_staff_user, name="create_staff_user"),
    path(
        "set_staff_password/<int:pk>/",
        views.set_staff_password,
        name="set_staff_password",
    ),
    path(
        "account_toggle_status/<int:pk>",
        views.account_toggle_status,
        name="account_toggle_status",
    ),
    # Source URLs
    path("sources/", views_source.SourceListView.as_view(), name="source_list"),
    path(
        "sources/create/", views_source.SourceCreateView.as_view(), name="source_create"
    ),
    path(
        "sources/<int:pk>/",
        views_source.SourceDetailView.as_view(),
        name="source_detail",
    ),
    path(
        "sources/<int:pk>/update/",
        views_source.SourceUpdateView.as_view(),
        name="source_update",
    ),
    path(
        "sources/<int:pk>/delete/",
        views_source.SourceDeleteView.as_view(),
        name="source_delete",
    ),
    path(
        "sources/<int:pk>/generate-keys/",
        views_source.generate_api_keys_view,
        name="generate_api_keys",
    ),
    path(
        "sources/<int:pk>/toggle-status/",
        views_source.toggle_source_status_view,
        name="toggle_source_status",
    ),
    path(
        "sources/api/copy-to-clipboard/",
        views_source.copy_to_clipboard_view,
        name="copy_to_clipboard",
    ),
    # Meeting Comments URLs
    path(
        "meetings/<slug:slug>/comments/add/",
        views.add_meeting_comment,
        name="add_meeting_comment",
    ),
    path(
        "meetings/<slug:slug>/comments/<int:comment_id>/edit/",
        views.edit_meeting_comment,
        name="edit_meeting_comment",
    ),
    path(
        "meetings/<slug:slug>/comments/<int:comment_id>/delete/",
        views.delete_meeting_comment,
        name="delete_meeting_comment",
    ),
    path(
        "meetings/<slug:slug>/set_meeting_candidate/",
        views.set_meeting_candidate,
        name="set_meeting_candidate",
    ),
    # Hiring Agency URLs
    path("agencies/", views.agency_list, name="agency_list"),
    path("agencies/create/", views.agency_create, name="agency_create"),
    path("agencies/<slug:slug>/", views.agency_detail, name="agency_detail"),
    path("agencies/<slug:slug>/update/", views.agency_update, name="agency_update"),
    path("agencies/<slug:slug>/delete/", views.agency_delete, name="agency_delete"),
    path(
        "agencies/<slug:slug>/candidates/",
        views.agency_candidates,
        name="agency_candidates",
    ),
    # path('agencies/<slug:slug>/send-message/', views.agency_detail_send_message, name='agency_detail_send_message'),
    # Agency Assignment Management URLs
    path(
        "agency-assignments/",
        views.agency_assignment_list,
        name="agency_assignment_list",
    ),
    path(
        "agency-assignments/create/",
        views.agency_assignment_create,
        name="agency_assignment_create",
    ),
    path(
        "agency-assignments/<slug:slug>/create/",
        views.agency_assignment_create,
        name="agency_assignment_create",
    ),
    path(
        "agency-assignments/<slug:slug>/",
        views.agency_assignment_detail,
        name="agency_assignment_detail",
    ),
    path(
        "agency-assignments/<slug:slug>/update/",
        views.agency_assignment_update,
        name="agency_assignment_update",
    ),
    path(
        "agency-assignments/<slug:slug>/extend-deadline/",
        views.agency_assignment_extend_deadline,
        name="agency_assignment_extend_deadline",
    ),
    # Agency Access Link URLs
    path(
        "agency-access-links/create/",
        views.agency_access_link_create,
        name="agency_access_link_create",
    ),
    path(
        "agency-access-links/<slug:slug>/",
        views.agency_access_link_detail,
        name="agency_access_link_detail",
    ),
    path(
        "agency-access-links/<slug:slug>/deactivate/",
        views.agency_access_link_deactivate,
        name="agency_access_link_deactivate",
    ),
    path(
        "agency-access-links/<slug:slug>/reactivate/",
        views.agency_access_link_reactivate,
        name="agency_access_link_reactivate",
    ),
    # Admin Message Center URLs (messaging functionality removed)
    # path('admin/messages/', views.admin_message_center, name='admin_message_center'),
    # path('admin/messages/compose/', views.admin_compose_message, name='admin_compose_message'),
    # path('admin/messages/<int:message_id>/', views.admin_message_detail, name='admin_message_detail'),
    # path('admin/messages/<int:message_id>/reply/', views.admin_message_reply, name='admin_message_reply'),
    # path('admin/messages/<int:message_id>/mark-read/', views.admin_mark_message_read, name='admin_mark_message_read'),
    # path('admin/messages/<int:message_id>/delete/', views.admin_delete_message, name='admin_delete_message'),
    # Agency Portal URLs (for external agencies)
    path("portal/login/", views.agency_portal_login, name="agency_portal_login"),
    path("portal/<int:pk>/reset/", views.portal_password_reset, name="portal_password_reset"),
    path(
        "portal/dashboard/",
        views.agency_portal_dashboard,
        name="agency_portal_dashboard",
    ),
    # Unified Portal URLs
    path("login/", views.portal_login, name="portal_login"),
    path(
        "candidate/dashboard/",
        views.candidate_portal_dashboard,
        name="candidate_portal_dashboard",
    ),
    path(
        "candidate/applications/<slug:slug>/",
        views.candidate_application_detail,
        name="candidate_application_detail",
    ),
    path(
        "portal/dashboard/",
        views.agency_portal_dashboard,
        name="agency_portal_dashboard",
    ),
    path(
        "portal/persons/",
        views.agency_portal_persons_list,
        name="agency_portal_persons_list",
    ),
    path(
        "portal/assignment/<slug:slug>/",
        views.agency_portal_assignment_detail,
        name="agency_portal_assignment_detail",
    ),
    path(
        "portal/assignment/<slug:slug>/submit-candidate/",
        views.agency_portal_submit_candidate_page,
        name="agency_portal_submit_candidate_page",
    ),
    path(
        "portal/submit-candidate/",
        views.agency_portal_submit_candidate,
        name="agency_portal_submit_candidate",
    ),
    path("portal/logout/", views.portal_logout, name="portal_logout"),
    # Agency Portal Candidate Management URLs
    path(
        "portal/candidates/<int:candidate_id>/edit/",
        views.agency_portal_edit_candidate,
        name="agency_portal_edit_candidate",
    ),
    path(
        "portal/candidates/<int:candidate_id>/delete/",
        views.agency_portal_delete_candidate,
        name="agency_portal_delete_candidate",
    ),
    # API URLs for messaging (removed)
    # path('api/agency/messages/<int:message_id>/', views.api_agency_message_detail, name='api_agency_message_detail'),
    # path('api/agency/messages/<int:message_id>/mark-read/', views.api_agency_mark_message_read, name='api_agency_mark_message_read'),
    # API URLs for candidate management
    path(
        "api/candidate/<int:candidate_id>/",
        views.api_candidate_detail,
        name="api_candidate_detail",
    ),
    # # Admin Notification API
    # path('api/admin/notification-count/', views.api_notification_count, name='admin_notification_count'),
    # # Agency Notification API
    # path('api/agency/notification-count/', views.api_notification_count, name='api_agency_notification_count'),
    # # SSE Notification Stream
    # path('api/notifications/stream/', views.notification_stream, name='notification_stream'),
    # # Notification URLs
    # path('notifications/', views.notification_list, name='notification_list'),
    # path('notifications/<int:notification_id>/', views.notification_detail, name='notification_detail'),
    # path('notifications/<int:notification_id>/mark-read/', views.notification_mark_read, name='notification_mark_read'),
    # path('notifications/<int:notification_id>/mark-unread/', views.notification_mark_unread, name='notification_mark_unread'),
    # path('notifications/<int:notification_id>/delete/', views.notification_delete, name='notification_delete'),
    # path('notifications/mark-all-read/', views.notification_mark_all_read, name='notification_mark_all_read'),
    # path('api/notification-count/', views.api_notification_count, name='api_notification_count'),
    # participants urls
    path(
        "participants/",
        views_frontend.ParticipantsListView.as_view(),
        name="participants_list",
    ),
    path(
        "participants/create/",
        views_frontend.ParticipantsCreateView.as_view(),
        name="participants_create",
    ),
    path(
        "participants/<slug:slug>/",
        views_frontend.ParticipantsDetailView.as_view(),
        name="participants_detail",
    ),
    path(
        "participants/<slug:slug>/update/",
        views_frontend.ParticipantsUpdateView.as_view(),
        name="participants_update",
    ),
    path(
        "participants/<slug:slug>/delete/",
        views_frontend.ParticipantsDeleteView.as_view(),
        name="participants_delete",
    ),
    # Email composition URLs
    path(
        "jobs/<slug:job_slug>/candidates/compose-email/",
        views.compose_candidate_email,
        name="compose_candidate_email",
    ),
    # Message URLs
    path("messages/", views.message_list, name="message_list"),
    path("messages/create/", views.message_create, name="message_create"),

    path("messages/<int:message_id>/", views.message_detail, name="message_detail"),
    path("messages/<int:message_id>/reply/", views.message_reply, name="message_reply"),
    path("messages/<int:message_id>/mark-read/", views.message_mark_read, name="message_mark_read"),
    path("messages/<int:message_id>/mark-unread/", views.message_mark_unread, name="message_mark_unread"),
    path("messages/<int:message_id>/delete/", views.message_delete, name="message_delete"),
    path("api/unread-count/", views.api_unread_count, name="api_unread_count"),

    # Documents
    path("documents/upload/<slug:slug>/", views.document_upload, name="document_upload"),
    path("documents/<int:document_id>/delete/", views.document_delete, name="document_delete"),
    path("documents/<int:document_id>/download/", views.document_download, name="document_download"),
    # Candidate Document Management URLs
    path("candidate/documents/upload/<slug:slug>/", views.document_upload, name="candidate_document_upload"),
    path("candidate/documents/<int:document_id>/delete/", views.document_delete, name="candidate_document_delete"),
    path("candidate/documents/<int:document_id>/download/", views.document_download, name="candidate_document_download"),
    path('jobs/<slug:job_slug>/candidates/compose_email/', views.compose_candidate_email, name='compose_candidate_email'),

    path('interview/partcipants/<slug:slug>/',views.create_interview_participants,name='create_interview_participants'),
    path('interview/email/<slug:slug>/',views.send_interview_email,name='send_interview_email'),
    # Candidate Signup
    path('candidate/signup/<slug:template_slug>/', views.candidate_signup, name='candidate_signup'),
    # Password Reset
    path('user/<int:pk>/password-reset/', views.portal_password_reset, name='portal_password_reset'),

    # # --- SCHEDULED INTERVIEW URLS (New Centralized Management) ---
    # path('interview/list/', views.interview_list, name='interview_list'),
    # path('interviews/<slug:slug>/', views.ScheduledInterviewDetailView.as_view(), name='scheduled_interview_detail'),
    # path('interviews/<slug:slug>/update/', views.ScheduledInterviewUpdateView.as_view(), name='update_scheduled_interview'),
    # path('interviews/<slug:slug>/delete/', views.ScheduledInterviewDeleteView.as_view(), name='delete_scheduled_interview'),

    #interview and meeting related urls
    path(
        "jobs/<slug:slug>/schedule-interviews/",
        views.schedule_interviews_view,
        name="schedule_interviews",
    ),
    path(
        "jobs/<slug:slug>/confirm-schedule-interviews/",
        views.confirm_schedule_interviews_view,
        name="confirm_schedule_interviews_view",
    ),

     path(
        "meetings/create-meeting/",
        views.ZoomMeetingCreateView.as_view(),
        name="create_meeting",
    ),
    # path(
    #     "meetings/meeting-details/<slug:slug>/",
    #     views.ZoomMeetingDetailsView.as_view(),
    #     name="meeting_details",
    # ),
    path(
        "meetings/update-meeting/<slug:slug>/",
        views.ZoomMeetingUpdateView.as_view(),
        name="update_meeting",
    ),
    path(
        "meetings/delete-meeting/<slug:slug>/",
        views.ZoomMeetingDeleteView,
        name="delete_meeting",
    ),
    # Candidate Meeting Scheduling/Rescheduling URLs
    path(
        "jobs/<slug:job_slug>/candidates/<int:candidate_pk>/schedule-meeting/",
        views.schedule_candidate_meeting,
        name="schedule_candidate_meeting",
    ),
    path(
        "api/jobs/<slug:job_slug>/candidates/<int:candidate_pk>/schedule-meeting/",
        views.api_schedule_candidate_meeting,
        name="api_schedule_candidate_meeting",
    ),
    path(
        "jobs/<slug:job_slug>/candidates/<int:candidate_pk>/reschedule-meeting/<int:interview_pk>/",
        views.reschedule_candidate_meeting,
        name="reschedule_candidate_meeting",
    ),
    path(
        "api/jobs/<slug:job_slug>/candidates/<int:candidate_pk>/reschedule-meeting/<int:interview_pk>/",
        views.api_reschedule_candidate_meeting,
        name="api_reschedule_candidate_meeting",
    ),
    # New URL for simple page-based meeting scheduling
    path(
        "jobs/<slug:slug>/candidates/<int:candidate_pk>/schedule-meeting-page/",
        views.schedule_meeting_for_candidate,
        name="schedule_meeting_for_candidate",
    ),
    path(
        "jobs/<slug:slug>/candidates/<int:candidate_pk>/delete_meeting_for_candidate/<int:meeting_id>/",
        views.delete_meeting_for_candidate,
        name="delete_meeting_for_candidate",
    ),


     path("interviews/meetings/", views.MeetingListView.as_view(), name="list_meetings"),

   # 1. Onsite Reschedule URL
    path(
        '<slug:slug>/candidate/<int:candidate_id>/onsite/reschedule/<int:meeting_id>/',
        views.reschedule_onsite_meeting,
        name='reschedule_onsite_meeting'
    ),

    # 2. Onsite Delete URL

    path(
        'job/<slug:slug>/candidates/<int:candidate_pk>/delete-onsite-meeting/<int:meeting_id>/',
        views.delete_onsite_meeting_for_candidate,
        name='delete_onsite_meeting_for_candidate'
    ),

    path(
        'job/<slug:slug>/candidate/<int:candidate_pk>/schedule/onsite/',
        views.schedule_onsite_meeting_for_candidate,
        name='schedule_onsite_meeting_for_candidate' # This is the name used in the button
    ),


    # Detail View (assuming slug is on ScheduledInterview)
    path("interviews/meetings/<slug:slug>/", views.meeting_details, name="meeting_details"),
   
]
