-- name: ClearSongs :exec
DELETE FROM song;

-- name: ClearSongsBySoundtrackId :exec
DELETE FROM song WHERE soundtrack_id = $1;

-- name: AddSong :exec
INSERT INTO song(uuid, soundtrack_id, song_name, path, file_name, hash) VALUES ($1, $2, $3, $4, $5, $6);

-- name: CheckSong :one
SELECT COUNT(*) FROM song WHERE soundtrack_id = $1 AND path = $2;

-- name: CheckSongWithHash :one
SELECT COUNT(*) FROM song WHERE hash = $1;

-- name: GetSongWithHash :one
SELECT * FROM song WHERE hash = $1;

-- name: UpdateSong :exec
UPDATE song SET song_name=$1, file_name=$2, path=$3 where hash=$4;

-- name: AddHashToSong :exec
UPDATE song SET hash=$1 where soundtrack_id = $2 AND path = $3;

-- name: FindSongsFromSoundtrack :many
SELECT *
FROM song
WHERE soundtrack_id = $1;

-- name: AddSongPlayed :exec
UPDATE song SET times_played = times_played + 1
WHERE soundtrack_id = $1 AND song_name = $2;

-- name: FetchAllSongs :many
SELECT * FROM song;

-- name: GetSongById :one
SELECT * FROM song WHERE id = $1;

-- name: RemoveBrokenSong :exec
DELETE FROM song WHERE soundtrack_id = $1 AND path = $2;

-- name: RemoveBrokenSongs :exec
DELETE FROM song WHERE id = ANY($1);
