# This file generated by `mix dagger.gen`. Please DO NOT EDIT.
defmodule Dagger.ObjectTypeDef do
  @moduledoc "A definition of a custom object defined in a Module."
  use Dagger.QueryBuilder
  @type t() :: %__MODULE__{}
  defstruct [:selection, :client]

  (
    @doc ""
    @spec constructor(t()) :: {:ok, Dagger.Function.t() | nil} | {:error, term()}
    def constructor(%__MODULE__{} = object_type_def) do
      selection = select(object_type_def.selection, "constructor")

      case execute(selection, object_type_def.client) do
        {:ok, nil} -> {:ok, nil}
        {:ok, data} -> Nestru.decode_from_map(data, Dagger.Function)
        error -> error
      end
    end
  )

  (
    @doc ""
    @spec description(t()) :: {:ok, Dagger.String.t()} | {:error, term()}
    def description(%__MODULE__{} = object_type_def) do
      selection = select(object_type_def.selection, "description")
      execute(selection, object_type_def.client)
    end
  )

  (
    @doc ""
    @spec fields(t()) :: {:ok, [Dagger.FieldTypeDef.t()]} | {:error, term()}
    def fields(%__MODULE__{} = object_type_def) do
      selection = select(object_type_def.selection, "fields")
      selection = select(selection, "description id name typeDef")

      with {:ok, data} <- execute(selection, object_type_def.client) do
        {:ok,
         data
         |> Enum.map(fn value ->
           elem_selection = Dagger.QueryBuilder.Selection.query()
           elem_selection = select(elem_selection, "loadFieldTypeDefFromID")
           elem_selection = arg(elem_selection, "id", value["id"])
           %Dagger.FieldTypeDef{selection: elem_selection, client: object_type_def.client}
         end)}
      end
    end
  )

  (
    @doc ""
    @spec functions(t()) :: {:ok, [Dagger.Function.t()]} | {:error, term()}
    def functions(%__MODULE__{} = object_type_def) do
      selection = select(object_type_def.selection, "functions")
      selection = select(selection, "args description id name returnType withArg withDescription")

      with {:ok, data} <- execute(selection, object_type_def.client) do
        {:ok,
         data
         |> Enum.map(fn value ->
           elem_selection = Dagger.QueryBuilder.Selection.query()
           elem_selection = select(elem_selection, "loadFunctionFromID")
           elem_selection = arg(elem_selection, "id", value["id"])
           %Dagger.Function{selection: elem_selection, client: object_type_def.client}
         end)}
      end
    end
  )

  (
    @doc "A unique identifier for this ObjectTypeDef."
    @spec id(t()) :: {:ok, Dagger.ObjectTypeDefID.t()} | {:error, term()}
    def id(%__MODULE__{} = object_type_def) do
      selection = select(object_type_def.selection, "id")
      execute(selection, object_type_def.client)
    end
  )

  (
    @doc ""
    @spec name(t()) :: {:ok, Dagger.String.t()} | {:error, term()}
    def name(%__MODULE__{} = object_type_def) do
      selection = select(object_type_def.selection, "name")
      execute(selection, object_type_def.client)
    end
  )

  (
    @doc ""
    @spec source_module_name(t()) :: {:ok, Dagger.String.t()} | {:error, term()}
    def source_module_name(%__MODULE__{} = object_type_def) do
      selection = select(object_type_def.selection, "sourceModuleName")
      execute(selection, object_type_def.client)
    end
  )
end
