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

-- name: ListWarehouses :many
SELECT * FROM warehouses
ORDER BY created_at DESC;

-- name: CreateWarehouse :one
INSERT INTO warehouses (name, description, address, created_at)
VALUES (
    sqlc.arg(name),
    sqlc.arg(description),
    sqlc.arg(address),
    sqlc.arg(created_at)
)
RETURNING *;

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

-- name: DeleteWarehouse :exec
DELETE FROM warehouses
WHERE id = sqlc.arg(id);
