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

-- name: ListContainers :many
SELECT * FROM containers
ORDER BY created_at DESC;

-- name: CreateContainer :one
INSERT INTO containers (shelf_id,name,container_type, description,max_capacity,metadata, created_at)
VALUES (
    sqlc.arg(shelf_id),
    sqlc.arg(name),
    sqlc.arg(container_type),
    sqlc.arg(description),
    sqlc.arg(max_capacity),
    sqlc.arg(metadata),
    sqlc.arg(created_at)
)
RETURNING *;

-- name: UpdateContainer :one
UPDATE containers
SET name = CASE WHEN sqlc.arg(name) = '' THEN name ELSE sqlc.arg(name) END,
    description = coalesce(sqlc.arg(description), description),
    container_type = coalesce(sqlc.narg(container_type), container_type),
    max_capacity = coalesce(sqlc.arg(max_capacity), max_capacity),
    metadata = coalesce(sqlc.arg(metadata), metadata),
    updated_at = sqlc.arg(updated_at)
WHERE id = sqlc.arg(id)
RETURNING *;

-- name: DeleteContainer :execrows
DELETE FROM containers
WHERE id = sqlc.arg(id);
