import { graphql } from "@/gql";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const CoursePageFragment = graphql(`
  fragment CoursePageFields on CoursePageInterface {
    title
    id
    slug
    content_type
    frontend_url
  }
`);

export const ATTENDANCE_CHECK_QUERY = graphql(`
  query attendanceCheckQuery($courseSessionId: ID!) {
    course_session_attendance_course(id: $courseSessionId) {
      id
      attendance_user_list {
        user_id
        status
      }
    }
  }
`);

export const ASSIGNMENT_COMPLETION_QUERY = graphql(`
  query assignmentCompletionQuery(
    $assignmentId: ID!
    $courseSessionId: ID!
    $learningContentId: ID
    $assignmentUserId: UUID
  ) {
    assignment(id: $assignmentId) {
      assignment_type
      needs_expert_evaluation
      max_points
      content_type
      effort_required
      evaluation_description
      evaluation_document_url
      evaluation_tasks
      id
      intro_text
      performance_objectives
      slug
      tasks
      title
      translation_key
      solution_sample {
        id
        url
      }
      competence_certificate {
        ...CoursePageFields
      }
    }
    assignment_completion(
      assignment_id: $assignmentId
      course_session_id: $courseSessionId
      assignment_user_id: $assignmentUserId
      learning_content_page_id: $learningContentId
    ) {
      id
      completion_status
      submitted_at
      evaluation_submitted_at
      evaluation_user {
        id
      }
      assignment_user {
        id
      }
      evaluation_points
      evaluation_max_points
      evaluation_passed
      edoniq_extended_time_flag
      completion_data
      task_completion_data
    }
  }
`);

export const COMPETENCE_NAVI_CERTIFICATE_QUERY = graphql(`
  query competenceCertificateQuery($courseSlug: String!, $courseSessionId: ID!) {
    competence_certificate_list(course_slug: $courseSlug) {
      ...CoursePageFields
      competence_certificates {
        ...CoursePageFields
        assignments {
          ...CoursePageFields
          assignment_type
          max_points
          completion(course_session_id: $courseSessionId) {
            id
            completion_status
            submitted_at
            evaluation_points
            evaluation_max_points
            evaluation_passed
          }
          learning_content {
            ...CoursePageFields
            circle {
              id
              title
              slug
            }
          }
        }
      }
    }
  }
`);

export const COURSE_SESSION_DETAIL_QUERY = graphql(`
  query courseSessionDetail($courseSessionId: ID!) {
    course_session(id: $courseSessionId) {
      id
      title
      course {
        id
        title
        slug
        enable_circle_documents
      }
      users {
        id
        user_id
        first_name
        last_name
        email
        avatar_url
        role
        circles {
          id
          title
          slug
        }
      }
      attendance_courses {
        id
        location
        trainer
        due_date {
          id
          start
          end
        }
        learning_content_id
        learning_content {
          id
          title
          circle {
            id
            title
            slug
          }
        }
      }
      assignments {
        id
        submission_deadline {
          id
          start
        }
        evaluation_deadline {
          id
          start
        }
        learning_content {
          id
          title
          content_assignment {
            id
            title
            assignment_type
          }
        }
      }
      edoniq_tests {
        id
        deadline {
          id
          start
          end
        }
        learning_content {
          id
          title
          content_assignment {
            id
            title
            assignment_type
          }
        }
      }
    }
  }
`);

export const COURSE_QUERY = graphql(`
  query courseQuery($slug: String!) {
    course(slug: $slug) {
      id
      title
      slug
      category_name
      enable_circle_documents
      action_competences {
        competence_id
        ...CoursePageFields
        performance_criteria {
          competence_id
          learning_unit {
            id
            slug
            evaluate_url
          }
          ...CoursePageFields
        }
      }
      learning_path {
        ...CoursePageFields
        topics {
          is_visible
          ...CoursePageFields
          circles {
            description
            goals
            ...CoursePageFields
            learning_sequences {
              icon
              ...CoursePageFields
              learning_units {
                evaluate_url
                ...CoursePageFields
                performance_criteria {
                  ...CoursePageFields
                }
                learning_contents {
                  can_user_self_toggle_course_completion
                  content_url
                  minutes
                  description
                  ...CoursePageFields
                  ... on LearningContentAssignmentObjectType {
                    assignment_type
                    content_assignment {
                      id
                      assignment_type
                    }
                    competence_certificate {
                      ...CoursePageFields
                    }
                  }
                  ... on LearningContentEdoniqTestObjectType {
                    checkbox_text
                    has_extended_time_test
                    content_assignment {
                      id
                      assignment_type
                    }
                    competence_certificate {
                      ...CoursePageFields
                    }
                  }
                  ... on LearningContentRichTextObjectType {
                    text
                  }
                }
              }
            }
          }
        }
      }
    }
  }
`);

export const DASHBOARD_CONFIG = graphql(`
  query dashboardConfig {
    dashboard_config {
      id
      slug
      name
      dashboard_type
    }
  }
`);

export const DASHBOARD_COURSE_SESSION_PROGRESS = graphql(`
  query dashboardProgress($courseId: ID!) {
    course_progress(course_id: $courseId) {
      _id
      course_id
      session_to_continue_id
      competence {
        _id
        total_count
        success_count
        fail_count
      }
      assignment {
        _id
        total_count
        points_max_count
        points_achieved_count
      }
    }
  }
`);

export const DASHBOARD_COURSE_STATISTICS = graphql(`
  query courseStatistics($courseId: ID!) {
    course_statistics(course_id: $courseId) {
      _id
      course_id
      course_title
      course_slug
      course_session_properties {
        _id
        sessions {
          id
          name
        }
        generations
        circles {
          id
          name
        }
      }
      course_session_selection_ids
      course_session_selection_metrics {
        _id
        session_count
        participant_count
        expert_count
      }
      attendance_day_presences {
        _id
        records {
          _id
          course_session_id
          generation
          circle_id
          due_date
          participants_present
          participants_total
          details_url
        }
        summary {
          _id
          days_completed
          participants_present
        }
      }
      feedback_responses {
        _id
        records {
          _id
          course_session_id
          generation
          circle_id
          experts
          satisfaction_average
          satisfaction_max
          details_url
        }
        summary {
          _id
          satisfaction_average
          satisfaction_max
          total_responses
        }
      }
      assignments {
        _id
        summary {
          _id
          completed_count
          average_passed
        }
        records {
          _id
          course_session_id
          course_session_assignment_id
          circle_id
          generation
          assignment_title
          assignment_type_translation_key
          details_url
          deadline
          metrics {
            _id
            passed_count
            failed_count
            unranked_count
            ranking_completed
            average_passed
          }
        }
      }
      competences {
        _id
        summary {
          _id
          success_total
          fail_total
        }
        records {
          _id
          course_session_id
          generation
          circle_id
          title
          success_count
          fail_count
          details_url
        }
      }
    }
  }
`);
