-- name: GetSystemRoleByName :one
SELECT * FROM core.roles
WHERE role_name = $1 AND is_system = TRUE;

-- name: CreateRoleAssignment :one
INSERT INTO core.role_assignments (role_id, person_id, org_id, scope_type, scope_id)
VALUES ($1, $2, $3, $4, $5)
RETURNING *;

-- name: GetRoleAssignmentsByPersonAndOrg :many
SELECT ra.*, r.role_name, r.display_name as role_display_name, r.permissions
FROM core.role_assignments ra
JOIN core.roles r ON r.role_id = ra.role_id
WHERE ra.person_id = $1 AND ra.org_id = $2;
