-- name: ResetSoundtrackIdSeq :one
SELECT setval('soundtrack_id_seq', (SELECT MAX(id) FROM soundtrack)+1);

-- name: GetSoundtrackNameById :one
SELECT soundtrack_name FROM soundtrack WHERE id = $1;

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

-- name: SetSoundtrackDeletionDate :exec
UPDATE soundtrack SET deleted=now() WHERE deleted IS NULL;

-- name: ClearSoundtracks :exec
DELETE FROM soundtrack;

-- name: UpdateSoundtrackName :exec
UPDATE soundtrack SET soundtrack_name=sqlc.arg(name), path=sqlc.arg(path), last_changed=now() WHERE id=sqlc.arg(id);

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

-- name: RemoveSoundtrackDeletionDate :exec
UPDATE soundtrack SET deleted=NULL WHERE id=$1;

-- name: GetIdBySoundtrackName :one
SELECT id FROM soundtrack WHERE soundtrack_name = $1;

-- name: InsertSoundtrack :one
INSERT INTO soundtrack (soundtrack_name, path, hash, added) VALUES ($1, $2, $3, now()) returning id;

-- name: InsertSoundtrackWithExistingId :exec
INSERT INTO soundtrack (id, soundtrack_name, path, hash, added) VALUES ($1, $2, $3, $4, now());

-- name: FindAllSoundtracks :many
SELECT *
FROM soundtrack
WHERE deleted IS NULL
ORDER BY soundtrack_name;

-- name: GetAllSoundtracksIncludingDeleted :many
SELECT *
FROM soundtrack
ORDER BY soundtrack_name;

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