-- name: CreateRolePermission :one
INSERT INTO role_permissions (
    role_id,
    permissions
 ) VALUES (
    $1, $2
 ) 
 RETURNING *;

-- name: GetPermission :many
SELECT permissions FROM role_permissions
WHERE role_id = $1;

-- name: UpdateRolePermission :exec
UPDATE role_permissions
  set 
  permissions = $2
WHERE role_id = $1;

-- name: IsAllowed :one
SELECT EXISTS (
    SELECT 1
    FROM user_roles ur 
    JOIN role_permissions rp ON ur.role_id = rp.role_id 
    WHERE ur.user_id = $1 AND rp.permissions = $2
);

-- name: DeleteRolePermission :exec
DELETE FROM role_permissions WHERE role_id = $1;

-- name: ListRolePermission :many
SELECT * FROM role_permissions
ORDER BY role_id;


