# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.ListTypeDef do
  @moduledoc """
  A definition of a list type in a Module.
  """

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

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

  @derive Dagger.ID

  defstruct [:query_builder, :client]

  @type t() :: %__MODULE__{}

  @doc """
  The type of the elements in the list.
  """
  @spec element_type_def(t()) :: Dagger.TypeDef.t()
  def element_type_def(%__MODULE__{} = list_type_def) do
    query_builder =
      list_type_def.query_builder |> QB.select("elementTypeDef")

    %Dagger.TypeDef{
      query_builder: query_builder,
      client: list_type_def.client
    }
  end

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

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

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

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