# ListUserRolesByRole

## Overview

ListUserRolesByRole retrieves all users assigned to a specific role. This query supports the DeactivateRole pre-check, where the system verifies whether a role has active UserRole assignments before allowing deactivation. It also enables administrators to review which users hold a given role for access audits and restructuring decisions.

## Business Rules

- Accepts a roleId as input
- Returns all User records associated with the role via UserRole join records
- Returns an empty array when the role has no user assignments — not an error
- The role must exist; a non-existent roleId returns an error

## Process Flow

```mermaid
flowchart TD
    A[Receive roleId] --> B{Role exists?}
    B -->|No| C[Return error: ROLE_NOT_FOUND]
    B -->|Yes| D[SELECT users via UserRole where roleId = input]
    D --> E{Any users found?}
    E -->|Yes| F[Return user records]
    E -->|No| G[Return empty array]
```

## External Dependencies

- None

## Error Scenarios

- **ROLE_NOT_FOUND**: Specified role ID does not exist

## Test Cases

- returns all users assigned to role
- returns empty array when role has no user assignments
- returns error when roleId does not exist
- returns multiple users when role has multiple user assignments
