# `Wenche.Systembruker`
[🔗](https://github.com/jarls-side-projects/elixir-wenche/blob/main/lib/wenche/systembruker.ex#L1)

System user flow for Altinn 3.

Ported from `wenche/systembruker.py` in the original Python Wenche project.

Altinn 3 requires that end-user systems register themselves in the system register
and create a system user for each organization they will act on behalf of.

## Required options

All public functions require a `:name` option — a short, lowercase identifier
for the system (e.g. `"kontira"`). This is used to build the system ID
(`<vendor_orgnr>_<name>`) and as the display name in Altinn.

`registrer_system/4` additionally requires a `:description` option — a map
with `"nb"`, `"nn"`, and `"en"` keys describing the system.

## Setup (run once)

1. `registrer_system/4` — registers the system in Altinn's system register
2. `opprett_forespoersel/4` — sends request to org for approval
3. User approves via confirmUrl in browser

For submission, use `Wenche.Maskinporten.get_systemuser_token/2` to get a token.

# `hent_forespoersel_status`

Gets the status of a system user request.

Returns `{:ok, response_map}` or `{:error, reason}`.

## Optional options

  * `:env` — `"test"` or `"prod"` (default: `"prod"`)

# `hent_systembrukere`

Gets all approved system users for the system.

Returns `{:ok, [system_user_map]}` or `{:error, reason}`.

## Required options

  * `:name` — short lowercase system identifier (e.g. `"kontira"`)

## Optional options

  * `:env` — `"test"` or `"prod"` (default: `"prod"`)

# `opprett_forespoersel`

Creates a system user request for the organization.

Returns `{:ok, %{id: uuid, status: "New", confirmUrl: url}}` or `{:error, reason}`.

The user must go to confirmUrl and approve in the browser.

## Required options

  * `:name` — short lowercase system identifier (e.g. `"kontira"`)

## Optional options

  * `:env` — `"test"` or `"prod"` (default: `"prod"`)

# `registrer_system`

Registers or updates the system in Altinn's system register.

Tries POST first. If the system already exists, uses PUT to update.

## Required options

  * `:name` — short lowercase system identifier (e.g. `"kontira"`)
  * `:description` — map with `"nb"`, `"nn"`, `"en"` keys

## Optional options

  * `:env` — `"test"` or `"prod"` (default: `"prod"`)

Returns `{:ok, response_map}` or `{:error, reason}`.

# `resource_ids`

Returns the list of resource IDs that the system requests access to.

Each entry is a short resource value string, e.g. `"app_brg_aarsregnskap-vanlig-202406"`.

# `rights`

Returns the raw rights structure used in Altinn API payloads.

# `system_id`

Returns the system ID in the format `<vendor_orgnr>_<name>`.

---

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