# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.EnumValueTypeDef do
  @moduledoc """
  A definition of a value in a custom enum defined in a Module.
  """

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

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

  @derive Dagger.ID

  defstruct [:query_builder, :client]

  @type t() :: %__MODULE__{}

  @doc """
  A doc string for the enum member, if any.
  """
  @spec description(t()) :: {:ok, String.t()} | {:error, term()}
  def description(%__MODULE__{} = enum_value_type_def) do
    query_builder =
      enum_value_type_def.query_builder |> QB.select("description")

    Client.execute(enum_value_type_def.client, query_builder)
  end

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

    Client.execute(enum_value_type_def.client, query_builder)
  end

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

    Client.execute(enum_value_type_def.client, query_builder)
  end

  @doc """
  The location of this enum member declaration.
  """
  @spec source_map(t()) :: Dagger.SourceMap.t() | nil
  def source_map(%__MODULE__{} = enum_value_type_def) do
    query_builder =
      enum_value_type_def.query_builder |> QB.select("sourceMap")

    %Dagger.SourceMap{
      query_builder: query_builder,
      client: enum_value_type_def.client
    }
  end

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

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

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

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