lib/actors/actor/entity/state.ex

defmodule Actors.Actor.Entity.EntityState do
  alias Eigr.Functions.Protocol.Actors.Actor

  defstruct system: nil, actor: nil, state_hash: nil, opts: []

  @type t :: %__MODULE__{
          system: String.t(),
          actor: Actor.t(),
          state_hash: binary(),
          opts: Keyword.t()
        }

  def unpack(%__MODULE__{actor: %Actor{}} = state) do
    state
  end

  def unpack(state) do
    %{state | actor: Actor.decode(state.actor)}
  end

  def pack(%__MODULE__{actor: %Actor{}} = state) do
    %{state | actor: Actor.encode(state.actor)}
  end

  def pack(state) do
    state
  end
end