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

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

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

  @derive Dagger.ID

  defstruct [:query_builder, :client]

  @type t() :: %__MODULE__{}

  @spec cached_token_reads(t()) :: {:ok, integer()} | {:error, term()}
  def cached_token_reads(%__MODULE__{} = llm_token_usage) do
    query_builder =
      llm_token_usage.query_builder |> QB.select("cachedTokenReads")

    Client.execute(llm_token_usage.client, query_builder)
  end

  @spec cached_token_writes(t()) :: {:ok, integer()} | {:error, term()}
  def cached_token_writes(%__MODULE__{} = llm_token_usage) do
    query_builder =
      llm_token_usage.query_builder |> QB.select("cachedTokenWrites")

    Client.execute(llm_token_usage.client, query_builder)
  end

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

    Client.execute(llm_token_usage.client, query_builder)
  end

  @spec input_tokens(t()) :: {:ok, integer()} | {:error, term()}
  def input_tokens(%__MODULE__{} = llm_token_usage) do
    query_builder =
      llm_token_usage.query_builder |> QB.select("inputTokens")

    Client.execute(llm_token_usage.client, query_builder)
  end

  @spec output_tokens(t()) :: {:ok, integer()} | {:error, term()}
  def output_tokens(%__MODULE__{} = llm_token_usage) do
    query_builder =
      llm_token_usage.query_builder |> QB.select("outputTokens")

    Client.execute(llm_token_usage.client, query_builder)
  end

  @spec total_tokens(t()) :: {:ok, integer()} | {:error, term()}
  def total_tokens(%__MODULE__{} = llm_token_usage) do
    query_builder =
      llm_token_usage.query_builder |> QB.select("totalTokens")

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

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

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