-- name: CreateTemplate :one
INSERT INTO templates (id, project_id, name, doc, version)
VALUES ($1, $2, $3, $4, 1)
RETURNING *;

-- name: GetTemplate :one
SELECT * FROM templates WHERE id = $1 AND project_id = $2;

-- name: ListTemplates :many
SELECT * FROM templates WHERE project_id = $1 ORDER BY created_at;

-- name: UpdateTemplate :one
UPDATE templates
SET name = $3, doc = $4, version = version + 1, updated_at = now()
WHERE id = $1 AND project_id = $2
RETURNING *;

-- name: DeleteTemplate :exec
DELETE FROM templates WHERE id = $1 AND project_id = $2;
