lib/xdr/transactions/operations/extend_footprint_ttl_result.ex

defmodule StellarBase.XDR.Operations.ExtendFootprintTTLResult do
  @moduledoc """
  Automatically generated by xdrgen
  DO NOT EDIT or your changes may be overwritten

  Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr

  Representation of Stellar `ExtendFootprintTTLResult` type.
  """

  @behaviour XDR.Declaration

  alias StellarBase.XDR.Void
  alias StellarBase.XDR.Operations.ExtendFootprintTTLResultCode

  @arms [
    EXTEND_FOOTPRINT_TTL_SUCCESS: Void,
    EXTEND_FOOTPRINT_TTL_MALFORMED: Void,
    EXTEND_FOOTPRINT_TTL_RESOURCE_LIMIT_EXCEEDED: Void,
    EXTEND_FOOTPRINT_TTL_INSUFFICIENT_REFUNDABLE_FEE: Void
  ]

  @type value ::
          Void.t()

  @type t :: %__MODULE__{value: value(), type: ExtendFootprintTTLResultCode.t()}

  defstruct [:value, :type]

  @spec new(value :: value(), type :: ExtendFootprintTTLResultCode.t()) :: t()
  def new(value, %ExtendFootprintTTLResultCode{} = type),
    do: %__MODULE__{value: value, type: type}

  @impl true
  def encode_xdr(%__MODULE__{value: value, type: type}) do
    type
    |> XDR.Union.new(@arms, value)
    |> XDR.Union.encode_xdr()
  end

  @impl true
  def encode_xdr!(%__MODULE__{value: value, type: type}) do
    type
    |> XDR.Union.new(@arms, value)
    |> XDR.Union.encode_xdr!()
  end

  @impl true
  def decode_xdr(bytes, spec \\ union_spec())

  def decode_xdr(bytes, spec) do
    case XDR.Union.decode_xdr(bytes, spec) do
      {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}}
      error -> error
    end
  end

  @impl true
  def decode_xdr!(bytes, spec \\ union_spec())

  def decode_xdr!(bytes, spec) do
    {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec)
    {new(value, type), rest}
  end

  @spec union_spec() :: XDR.Union.t()
  defp union_spec do
    nil
    |> ExtendFootprintTTLResultCode.new()
    |> XDR.Union.new(@arms)
  end
end