-- name: CreateFlagsGame :one
INSERT INTO app_flags_games (uid, tags, question_amount)
VALUES ($1, $2, $3)
RETURNING game_id, game_seed;

-- name: GetFlagsGame :one
SELECT * FROM app_flags_games WHERE game_id = $1 LIMIT 1;

-- name: UpdateFlagsGame :exec
UPDATE app_flags_games
SET question_current = $1, last_activity = CURRENT_TIMESTAMP
WHERE game_id = $2;

-- name: UpdateQuestionCorrect :exec
UPDATE app_flags_games
SET questions_correct = (
    SELECT COUNT(*)
    FROM app_flags_games_answers
    WHERE game_id $1 AND correct = TRUE
)
WHERE game_id = $1;
