# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.FunctionCallArgValue do
  @moduledoc """
  A value passed as a named argument to a function call.
  """

  use Dagger.Core.Base, kind: :object, name: "FunctionCallArgValue"

  alias Dagger.Core.Client
  alias Dagger.Core.QueryBuilder, as: QB

  @derive Dagger.ID

  defstruct [:query_builder, :client]

  @type t() :: %__MODULE__{}

  @doc """
  A unique identifier for this FunctionCallArgValue.
  """
  @spec id(t()) :: {:ok, Dagger.FunctionCallArgValueID.t()} | {:error, term()}
  def id(%__MODULE__{} = function_call_arg_value) do
    query_builder =
      function_call_arg_value.query_builder |> QB.select("id")

    Client.execute(function_call_arg_value.client, query_builder)
  end

  @doc """
  The name of the argument.
  """
  @spec name(t()) :: {:ok, String.t()} | {:error, term()}
  def name(%__MODULE__{} = function_call_arg_value) do
    query_builder =
      function_call_arg_value.query_builder |> QB.select("name")

    Client.execute(function_call_arg_value.client, query_builder)
  end

  @doc """
  The value of the argument represented as a JSON serialized string.
  """
  @spec value(t()) :: {:ok, Dagger.JSON.t()} | {:error, term()}
  def value(%__MODULE__{} = function_call_arg_value) do
    query_builder =
      function_call_arg_value.query_builder |> QB.select("value")

    Client.execute(function_call_arg_value.client, query_builder)
  end
end

defimpl Jason.Encoder, for: Dagger.FunctionCallArgValue do
  def encode(function_call_arg_value, opts) do
    {:ok, id} = Dagger.FunctionCallArgValue.id(function_call_arg_value)
    Jason.Encode.string(id, opts)
  end
end

defimpl Nestru.Decoder, for: Dagger.FunctionCallArgValue do
  def decode_fields_hint(_struct, _context, id) do
    {:ok, Dagger.Client.load_function_call_arg_value_from_id(Dagger.Global.dag(), id)}
  end
end
