lib/toolbox/runtime/stage/unit.ex

defmodule Toolbox.Runtime.Stage.Unit do
  @moduledoc """
  Struct representing a unit.
  """

  alias __MODULE__, as: U

  defstruct id: "",
            state: %{},
            attributes: %{}

  @type t :: %U{
          id: binary(),
          state: any(),
          attributes: map()
        }

  @spec new(id :: binary(), state :: any(), attributes :: map()) :: t()
  def new(id, state, attributes) do
    %U{id: id, state: state, attributes: attributes}
  end

  @spec id(t()) :: binary()
  def id(%U{id: id}), do: id

  @spec state(t()) :: any()
  def state(%U{state: state}), do: state

  @spec set_state(t(), state :: any()) :: t()
  def set_state(%U{} = u, state), do: %U{u | state: state}

  @spec attributes(t()) :: map()
  def attributes(%U{attributes: attributes}), do: attributes
end