# `BB.Server.ParamResolution`
[🔗](https://github.com/beam-bots/bb/blob/main/lib/bb/server/param_resolution.ex#L5)

Shared parameter resolution logic for wrapper servers.

This module provides functions for resolving `ParamRef` values in options
and subscribing to parameter change notifications. Used by:

- `BB.Actuator.Server`
- `BB.Sensor.Server`
- `BB.Controller.Server`
- `BB.Command.Server`

## Usage

In your server's `init/1`:

    {param_subscriptions, resolved_opts} =
      ParamResolution.resolve_and_subscribe(raw_opts, robot_module)

In `handle_info/2` for parameter changes:

    def handle_info({:bb, [:param | param_path], %{payload: %ParameterChanged{}}}, state) do
      ParamResolution.handle_param_change(
        param_path,
        state.param_subscriptions,
        state.raw_opts,
        robot_module,
        fn new_resolved ->
          # Call user's handle_options callback
        end
      )
    end

# `subscriptions`

```elixir
@type subscriptions() :: %{required([atom()]) =&gt; atom()}
```

# `handle_change`

```elixir
@spec handle_change(
  [atom()],
  subscriptions(),
  keyword(),
  module() | BB.Robot.State.t()
) ::
  {:changed, keyword()} | :ignored
```

Handle a parameter change message.

Checks if the changed parameter is one we're subscribed to,
re-resolves all options, and calls the provided callback with the new options.

Returns `{:changed, new_resolved}` if the parameter was tracked,
or `:ignored` if not.

# `resolve`

```elixir
@spec resolve(
  keyword(),
  module() | BB.Robot.State.t()
) :: {subscriptions(), keyword()}
```

Resolve ParamRefs in options without subscribing.

Takes either a robot module or a `BB.Robot.State` struct directly.
Passing the state directly avoids a lookup and potential deadlock
during init when the Runtime is still starting.

# `resolve_and_subscribe`

```elixir
@spec resolve_and_subscribe(
  keyword(),
  module() | BB.Robot.State.t()
) :: {subscriptions(), keyword()}
```

Resolve ParamRefs in options and subscribe to parameter change topics.

Returns `{subscriptions_map, resolved_opts}` where:
- `subscriptions_map` maps parameter paths to option keys
- `resolved_opts` has ParamRefs replaced with their current values

This is a convenience function that calls `resolve/2` and `subscribe/2`.

# `subscribe`

```elixir
@spec subscribe(module(), subscriptions()) :: :ok
```

Subscribe to parameter change topics for tracked parameters.

---

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