-- user_albums.sql
-- name: GetUserAlbums :many
SELECT ua.*, a.name AS album_name, a.artist AS album_artist, a.release_date, a.album_art_url
FROM user_albums ua
JOIN albums a ON ua.album_id = a.id
WHERE ua.user_id = $1;

-- name: GetUserAlbum :one
SELECT ua.*, a.name AS album_name, a.artist AS album_artist, a.release_date, a.album_art_url
FROM user_albums ua
JOIN albums a ON ua.album_id = a.id
WHERE ua.user_id = $1 AND ua.album_id = $2;

-- name: AddUserAlbum :exec
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6);

-- name: RemoveUserAlbum :exec
DELETE FROM user_albums WHERE user_id = $1 AND album_id = $2;

-- name: UpdateUserAlbumStatus :exec
INSERT INTO user_albums (user_id, album_id, album_owned, album_want,
is_vinyl, is_cd) VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT (user_id, album_id) DO UPDATE SET
album_owned = EXCLUDED.album_owned,
album_want = EXCLUDED.album_want,
is_vinyl = EXCLUDED.is_vinyl,
is_cd = EXCLUDED.is_cd;