# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.Cloud do
  @moduledoc """
  Dagger Cloud configuration and state
  """

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

  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 Cloud.
  """
  @spec id(t()) :: {:ok, Dagger.CloudID.t()} | {:error, term()}
  def id(%__MODULE__{} = cloud) do
    query_builder =
      cloud.query_builder |> QB.select("id")

    Client.execute(cloud.client, query_builder)
  end

  @doc """
  The trace URL for the current session
  """
  @spec trace_url(t()) :: {:ok, String.t()} | {:error, term()}
  def trace_url(%__MODULE__{} = cloud) do
    query_builder =
      cloud.query_builder |> QB.select("traceURL")

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

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

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