# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.ErrorValue do
  @moduledoc """
  Dagger.ErrorValue
  """

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

  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 ErrorValue.
  """
  @spec id(t()) :: {:ok, Dagger.ErrorValueID.t()} | {:error, term()}
  def id(%__MODULE__{} = error_value) do
    query_builder =
      error_value.query_builder |> QB.select("id")

    Client.execute(error_value.client, query_builder)
  end

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

    Client.execute(error_value.client, query_builder)
  end

  @doc """
  The value.
  """
  @spec value(t()) :: {:ok, Dagger.JSON.t()} | {:error, term()}
  def value(%__MODULE__{} = error_value) do
    query_builder =
      error_value.query_builder |> QB.select("value")

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

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

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