-- name: GetStat :one
SELECT * FROM stat WHERE id = ? AND scope_id = ?;

-- name: ListStats :many
SELECT * FROM stat WHERE scope_id = ? ORDER BY is_primary DESC, name;

-- name: InsertStat :execresult
INSERT INTO stat (scope_id, name, description, weight, allowed_amounts, is_primary)
VALUES (?, ?, ?, ?, ?, ?);

-- name: UpdateStat :exec
UPDATE stat
SET name = ?,
    description = ?,
    weight = ?,
    allowed_amounts = ?,
    is_primary = ?
WHERE id = ? AND scope_id = ?;

-- name: DeleteStat :exec
DELETE FROM stat WHERE id = ? AND scope_id = ?;

-- name: DeleteAllItemStatProgressByStatId :exec
DELETE FROM item_stat_progress WHERE stat_id = ?;

-- name: DeleteAllProjectRequirementStatByStatId :exec
DELETE FROM project_requirement_stat WHERE stat_id = ?;

-- name: DeleteAllScopeStats :exec
DELETE FROM stat WHERE scope_id = ?;
