-- name: CreateAssessmentAttempt :one
INSERT INTO assessment_attempts (
    user_id,
    total_questions,
    correct_answers,
    score_percentage,
    knowledge_level
)
VALUES (
    $1, -- user_id
    $2, -- total_questions
    $3, -- correct_answers
    $4, -- score_percentage
    $5  -- knowledge_level
)
RETURNING
    id,
    user_id,
    total_questions,
    correct_answers,
    score_percentage,
    knowledge_level,
    completed_at;

-- -- name: CreateAssessmentAnswer :exec
-- INSERT INTO assessment_answers (
--     attempt_id,
--     question_id,
--     selected_option_id,
--     short_answer,
--     is_correct
-- )
-- VALUES (
--     $1, -- attempt_id
--     $2, -- question_id
--     $3, -- selected_option_id
--     $4, -- short_answer
--     $5  -- is_correct
-- );

-- name: GetAssessmentOptionByID :one
SELECT
    id,
    question_id,
    option_text,
    is_correct
FROM assessment_question_options
WHERE id = $1
LIMIT 1;

-- name: GetCorrectOptionForQuestion :one
SELECT
    id
FROM assessment_question_options
WHERE question_id = $1
  AND is_correct = TRUE
LIMIT 1;

-- name: GetLatestAssessmentAttempt :one
SELECT *
FROM assessment_attempts
WHERE user_id = $1
ORDER BY completed_at DESC
LIMIT 1;

-- name: CreateAssessmentQuestion :one
INSERT INTO assessment_questions (
    title,
    description,
    question_type,
    difficulty_level
)
VALUES ($1, $2, $3, $4)
RETURNING *;

-- name: CreateAssessmentQuestionOption :exec
INSERT INTO assessment_question_options (
    question_id,
    option_text,
    is_correct
)
VALUES ($1, $2, $3);

-- name: GetActiveAssessmentQuestions :many
SELECT *
FROM assessment_questions
WHERE is_active = TRUE
ORDER BY difficulty_level, id;

-- name: GetQuestionOptions :many
SELECT *
FROM assessment_question_options
WHERE question_id = $1;
