# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.CacheVolume do
  @moduledoc """
  A directory whose contents persist across runs.
  """

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

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

  @derive Dagger.ID

  defstruct [:query_builder, :client]

  @type t() :: %__MODULE__{}

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

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

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

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