-- name: ResetGameIdSeq :one
SELECT setval('game_id_seq', (SELECT MAX(id) FROM game)+1);

-- name: GetGameNameById :one
SELECT game_name FROM game WHERE id = $1;

-- name: GetGameById :one
SELECT * 
FROM game 
WHERE id = $1 
AND deleted IS NULL;

-- name: SetGameDeletionDate :exec
UPDATE game SET deleted=now() WHERE deleted IS NULL;

-- name: ClearGames :exec
DELETE FROM game;

-- name: UpdateGameName :exec
UPDATE game SET game_name=sqlc.arg(name), path=sqlc.arg(path), last_changed=now() WHERE id=sqlc.arg(id);

-- name: UpdateGameHash :exec
UPDATE game SET hash=sqlc.arg(hash), last_changed=now() WHERE id=sqlc.arg(id);

-- name: RemoveDeletionDate :exec
UPDATE game SET deleted=NULL WHERE id=$1;

-- name: GetIdByGameName :one
SELECT id FROM game WHERE game_name = $1;

-- name: InsertGame :one
INSERT INTO game (game_name, path, hash, added) VALUES ($1, $2, $3, now()) returning id;

-- name: InsertGameWithExistingId :exec
INSERT INTO game (id, game_name, path, hash, added) VALUES ($1, $2, $3, $4, now());

-- name: FindAllGames :many
SELECT *
FROM game
WHERE deleted IS NULL
ORDER BY game_name;

-- name: GetAllGamesIncludingDeleted :many
SELECT *
FROM game
ORDER BY game_name;

-- name: AddGamePlayed :exec
UPDATE game SET times_played = times_played + 1, last_played = now() WHERE id = $1;
