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

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

  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 scalar, if any.
  """
  @spec description(t()) :: {:ok, String.t()} | {:error, term()}
  def description(%__MODULE__{} = scalar_type_def) do
    query_builder =
      scalar_type_def.query_builder |> QB.select("description")

    Client.execute(scalar_type_def.client, query_builder)
  end

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

    Client.execute(scalar_type_def.client, query_builder)
  end

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

    Client.execute(scalar_type_def.client, query_builder)
  end

  @doc """
  If this ScalarTypeDef is associated with a Module, the name of the module. Unset otherwise.
  """
  @spec source_module_name(t()) :: {:ok, String.t()} | {:error, term()}
  def source_module_name(%__MODULE__{} = scalar_type_def) do
    query_builder =
      scalar_type_def.query_builder |> QB.select("sourceModuleName")

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

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

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