-- name: ListResourceKeys :many
SELECT * FROM core.resource_keys
ORDER BY resource_key ASC;

-- name: GetResourceKey :one
-- Single-key lookup for the rule-authoring handler: rule_type is derived
-- server-side from the key's kind, never taken from client input.
SELECT * FROM core.resource_keys
WHERE resource_key = $1;

-- name: ListResourceKeyLabels :many
-- Display metadata for entitlement rendering: each key's human-friendly
-- label plus its owning integration's display name. LEFT JOIN because
-- provider NULL = platform-owned/pooled (see the resource_keys DDL
-- comment); such keys render un-attributed.
SELECT rk.resource_key, rk.display_name, rk.unit,
       COALESCE(p.display_name, '') AS provider_display_name
FROM core.resource_keys rk
LEFT JOIN core.providers p ON p.provider = rk.provider
ORDER BY rk.resource_key ASC;
