-- name: ListCategories :many
SELECT id, name, sort_order, created_at, updated_at
FROM categories
ORDER BY sort_order ASC, id ASC;

-- name: GetCategory :one
SELECT id, name, sort_order, created_at, updated_at
FROM categories
WHERE id = $1;

-- name: CreateCategory :one
INSERT INTO categories (name, sort_order)
VALUES ($1, $2)
RETURNING id, name, sort_order, created_at, updated_at;

-- name: UpdateCategory :one
UPDATE categories
SET name = $2,
    sort_order = $3,
    updated_at = NOW()
WHERE id = $1
RETURNING id, name, sort_order, created_at, updated_at;

-- name: DeleteCategory :exec
DELETE FROM categories WHERE id = $1;
