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

-- name: ListRooms :many
SELECT * FROM rooms
ORDER BY created_at DESC;

-- name: CreateRoom :one
INSERT INTO rooms (warehouse_id,name, description, created_at)
VALUES (
    sqlc.arg(warehouse_id),
    sqlc.arg(name),
    sqlc.arg(description),
    sqlc.arg(created_at)
)
RETURNING *;

-- name: UpdateRoom :one
UPDATE rooms
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: DeleteRoom :exec
DELETE FROM rooms
WHERE id = sqlc.arg(id);
