#######################################################
# This file was auto-generated by elixir_bindings.zig #
#              Do not manually modify.                #
#######################################################

defmodule TigerBeetlex.CreateTransfersResult do
  @moduledoc """
  See [CreateTransfersResult](https://docs.tigerbeetle.com/reference/requests/create_transfers#).
  """

  use TypedStruct

  alias TigerBeetlex.CreateTransferResult

  typedstruct do
    field :index, non_neg_integer(), default: 0
    field :result, atom()
  end

  @doc """
  Creates a `TigerBeetlex.CreateTransfersResult` struct from its binary representation.
  """
  @spec from_binary(binary :: <<_::64>>) :: t()
  def from_binary(<<_::binary-size(8)>> = bin) do
    <<
      index::unsigned-little-32,
      result::unsigned-little-32
    >> = bin

    %__MODULE__{
      index: index,
      result: CreateTransferResult.to_atom(result)
    }
  end

  @doc """
  Converts a `TigerBeetlex.CreateTransfersResult` struct to its binary representation.
  """
  @spec to_binary(struct :: t()) :: <<_::64>>
  def to_binary(struct) do
    %__MODULE__{
      index: index,
      result: result
    } = struct

    <<
      index::unsigned-little-32,
      CreateTransferResult.from_atom(result)::unsigned-little-32
    >>
  end
end
