-- name: GetCabinetByID :one
SELECT * FROM cabinets
WHERE id = sqlc.arg(id);

-- name: ListCabinets :many
SELECT * FROM cabinets
ORDER BY created_at DESC;

-- name: CreateCabinet :one
INSERT INTO cabinets (room_id,name, description, created_at)
VALUES (
    sqlc.arg(room_id),
    sqlc.arg(name),
    sqlc.arg(description),
    sqlc.arg(created_at)
)
RETURNING *;

-- name: UpdateCabinet :one
UPDATE cabinets
SET name = CASE WHEN sqlc.arg(name) = '' THEN name ELSE sqlc.arg(name) END,
    description = coalesce(sqlc.arg(description), description),
    updated_at = sqlc.arg(updated_at)
WHERE id = sqlc.arg(id)
RETURNING *;

-- name: DeleteCabinet :execrows
DELETE FROM cabinets
WHERE id = sqlc.arg(id);
