-- name: GetActiveRulesBySetID :many
SELECT * FROM core.entitlement_set_rules
WHERE set_id = $1 AND is_active = TRUE
ORDER BY resource_key ASC;

-- name: CreateEntitlementSetRule :one
INSERT INTO core.entitlement_set_rules (set_id, rule_type, resource_key, resource_value, resource_per_unit, stacking_policy, reset_period, credit_amount, credit_currency, description)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING *;

-- name: UpdateEntitlementSetRule :one
UPDATE core.entitlement_set_rules
SET resource_value = $2, resource_per_unit = $3, stacking_policy = $4, description = $5, is_active = $6
WHERE rule_id = $1
RETURNING *;

-- name: DeleteEntitlementSetRule :exec
DELETE FROM core.entitlement_set_rules
WHERE rule_id = $1;
