# `PhoenixKit.Users.Role`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.87/lib/phoenix_kit/users/role.ex#L1)

Role schema for PhoenixKit authorization system.

This schema defines user roles that can be assigned to users for authorization purposes.

## Fields

- `name`: Role name (unique, required for identification)
- `description`: Human-readable description of the role
- `is_system_role`: Whether this is a system-defined role that shouldn't be deleted

## System Roles

PhoenixKit includes three built-in system roles:

- **Owner**: System owner with full access (assigned to first user automatically)
- **Admin**: Administrator with elevated privileges
- **User**: Standard user with basic access (default for new users)

## Security Features

- System roles cannot be deleted
- Role names are unique
- Automatic assignment of User role to new registrations
- Automatic assignment of Owner role to first user

# `t`

```elixir
@type t() :: %PhoenixKit.Users.Role{
  __meta__: term(),
  description: String.t() | nil,
  inserted_at: DateTime.t(),
  is_system_role: boolean(),
  name: String.t(),
  role_assignments: term(),
  updated_at: DateTime.t(),
  users: term(),
  uuid: UUIDv7.t() | nil
}
```

# `changeset`

A role changeset for creating and updating roles.

## Parameters

- `role`: The role struct to modify
- `attrs`: Attributes to update

## Examples

    iex> changeset(%Role{}, %{name: "Manager", description: "Department manager"})
    %Ecto.Changeset{valid?: true}

    iex> changeset(%Role{}, %{name: ""})
    %Ecto.Changeset{valid?: false}

# `system_role?`

Checks if a role name is a system role.

## Examples
    iex> system_role?(system_roles().owner)
    true

    iex> system_role?("Owner")
    true

    iex> system_role?("Manager")
    false

# `system_roles`

Returns the map of system role names.

## Examples

    iex> system_roles()
    %{owner: "Owner", admin: "Admin", user: "User"}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
