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

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

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

    Client.execute(env.client, query_builder)
  end

  @doc """
  Retrieves an input binding by name
  """
  @spec input(t(), String.t()) :: Dagger.Binding.t()
  def input(%__MODULE__{} = env, name) do
    query_builder =
      env.query_builder |> QB.select("input") |> QB.put_arg("name", name)

    %Dagger.Binding{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Returns all input bindings provided to the environment
  """
  @spec inputs(t()) :: {:ok, [Dagger.Binding.t()]} | {:error, term()}
  def inputs(%__MODULE__{} = env) do
    query_builder =
      env.query_builder |> QB.select("inputs") |> QB.select("id")

    with {:ok, items} <- Client.execute(env.client, query_builder) do
      {:ok,
       for %{"id" => id} <- items do
         %Dagger.Binding{
           query_builder:
             QB.query()
             |> QB.select("loadBindingFromID")
             |> QB.put_arg("id", id),
           client: env.client
         }
       end}
    end
  end

  @doc """
  Retrieves an output binding by name
  """
  @spec output(t(), String.t()) :: Dagger.Binding.t()
  def output(%__MODULE__{} = env, name) do
    query_builder =
      env.query_builder |> QB.select("output") |> QB.put_arg("name", name)

    %Dagger.Binding{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Returns all declared output bindings for the environment
  """
  @spec outputs(t()) :: {:ok, [Dagger.Binding.t()]} | {:error, term()}
  def outputs(%__MODULE__{} = env) do
    query_builder =
      env.query_builder |> QB.select("outputs") |> QB.select("id")

    with {:ok, items} <- Client.execute(env.client, query_builder) do
      {:ok,
       for %{"id" => id} <- items do
         %Dagger.Binding{
           query_builder:
             QB.query()
             |> QB.select("loadBindingFromID")
             |> QB.put_arg("id", id),
           client: env.client
         }
       end}
    end
  end

  @doc """
  Create or update a binding of type Address in the environment
  """
  @spec with_address_input(t(), String.t(), Dagger.Address.t(), String.t()) :: Dagger.Env.t()
  def with_address_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withAddressInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Address output to be assigned in the environment
  """
  @spec with_address_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_address_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withAddressOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type CacheVolume in the environment
  """
  @spec with_cache_volume_input(t(), String.t(), Dagger.CacheVolume.t(), String.t()) ::
          Dagger.Env.t()
  def with_cache_volume_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withCacheVolumeInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired CacheVolume output to be assigned in the environment
  """
  @spec with_cache_volume_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_cache_volume_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withCacheVolumeOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type Changeset in the environment
  """
  @spec with_changeset_input(t(), String.t(), Dagger.Changeset.t(), String.t()) :: Dagger.Env.t()
  def with_changeset_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withChangesetInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Changeset output to be assigned in the environment
  """
  @spec with_changeset_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_changeset_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withChangesetOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type Cloud in the environment
  """
  @spec with_cloud_input(t(), String.t(), Dagger.Cloud.t(), String.t()) :: Dagger.Env.t()
  def with_cloud_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withCloudInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Cloud output to be assigned in the environment
  """
  @spec with_cloud_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_cloud_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withCloudOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type Container in the environment
  """
  @spec with_container_input(t(), String.t(), Dagger.Container.t(), String.t()) :: Dagger.Env.t()
  def with_container_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withContainerInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Container output to be assigned in the environment
  """
  @spec with_container_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_container_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withContainerOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Installs the current module into the environment, exposing its functions to the model

  Contextual path arguments will be populated using the environment's workspace.
  """
  @spec with_current_module(t()) :: Dagger.Env.t()
  def with_current_module(%__MODULE__{} = env) do
    query_builder =
      env.query_builder |> QB.select("withCurrentModule")

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type Directory in the environment
  """
  @spec with_directory_input(t(), String.t(), Dagger.Directory.t(), String.t()) :: Dagger.Env.t()
  def with_directory_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withDirectoryInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Directory output to be assigned in the environment
  """
  @spec with_directory_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_directory_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withDirectoryOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type EnvFile in the environment
  """
  @spec with_env_file_input(t(), String.t(), Dagger.EnvFile.t(), String.t()) :: Dagger.Env.t()
  def with_env_file_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withEnvFileInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired EnvFile output to be assigned in the environment
  """
  @spec with_env_file_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_env_file_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withEnvFileOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type Env in the environment
  """
  @spec with_env_input(t(), String.t(), Dagger.Env.t(), String.t()) :: Dagger.Env.t()
  def with_env_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withEnvInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Env output to be assigned in the environment
  """
  @spec with_env_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_env_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withEnvOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type File in the environment
  """
  @spec with_file_input(t(), String.t(), Dagger.File.t(), String.t()) :: Dagger.Env.t()
  def with_file_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withFileInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired File output to be assigned in the environment
  """
  @spec with_file_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_file_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withFileOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type GitRef in the environment
  """
  @spec with_git_ref_input(t(), String.t(), Dagger.GitRef.t(), String.t()) :: Dagger.Env.t()
  def with_git_ref_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withGitRefInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired GitRef output to be assigned in the environment
  """
  @spec with_git_ref_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_git_ref_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withGitRefOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type GitRepository in the environment
  """
  @spec with_git_repository_input(t(), String.t(), Dagger.GitRepository.t(), String.t()) ::
          Dagger.Env.t()
  def with_git_repository_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withGitRepositoryInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired GitRepository output to be assigned in the environment
  """
  @spec with_git_repository_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_git_repository_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withGitRepositoryOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type JSONValue in the environment
  """
  @spec with_json_value_input(t(), String.t(), Dagger.JSONValue.t(), String.t()) :: Dagger.Env.t()
  def with_json_value_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withJSONValueInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired JSONValue output to be assigned in the environment
  """
  @spec with_json_value_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_json_value_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withJSONValueOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Installs a module into the environment, exposing its functions to the model

  Contextual path arguments will be populated using the environment's workspace.
  """
  @spec with_module(t(), Dagger.Module.t()) :: Dagger.Env.t()
  def with_module(%__MODULE__{} = env, module) do
    query_builder =
      env.query_builder |> QB.select("withModule") |> QB.put_arg("module", Dagger.ID.id!(module))

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type ModuleConfigClient in the environment
  """
  @spec with_module_config_client_input(
          t(),
          String.t(),
          Dagger.ModuleConfigClient.t(),
          String.t()
        ) :: Dagger.Env.t()
  def with_module_config_client_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withModuleConfigClientInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired ModuleConfigClient output to be assigned in the environment
  """
  @spec with_module_config_client_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_module_config_client_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withModuleConfigClientOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type Module in the environment
  """
  @spec with_module_input(t(), String.t(), Dagger.Module.t(), String.t()) :: Dagger.Env.t()
  def with_module_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withModuleInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Module output to be assigned in the environment
  """
  @spec with_module_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_module_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withModuleOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type ModuleSource in the environment
  """
  @spec with_module_source_input(t(), String.t(), Dagger.ModuleSource.t(), String.t()) ::
          Dagger.Env.t()
  def with_module_source_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withModuleSourceInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired ModuleSource output to be assigned in the environment
  """
  @spec with_module_source_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_module_source_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withModuleSourceOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type SearchResult in the environment
  """
  @spec with_search_result_input(t(), String.t(), Dagger.SearchResult.t(), String.t()) ::
          Dagger.Env.t()
  def with_search_result_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withSearchResultInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired SearchResult output to be assigned in the environment
  """
  @spec with_search_result_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_search_result_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withSearchResultOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type SearchSubmatch in the environment
  """
  @spec with_search_submatch_input(t(), String.t(), Dagger.SearchSubmatch.t(), String.t()) ::
          Dagger.Env.t()
  def with_search_submatch_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withSearchSubmatchInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired SearchSubmatch output to be assigned in the environment
  """
  @spec with_search_submatch_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_search_submatch_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withSearchSubmatchOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type Secret in the environment
  """
  @spec with_secret_input(t(), String.t(), Dagger.Secret.t(), String.t()) :: Dagger.Env.t()
  def with_secret_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withSecretInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Secret output to be assigned in the environment
  """
  @spec with_secret_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_secret_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withSecretOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type Service in the environment
  """
  @spec with_service_input(t(), String.t(), Dagger.Service.t(), String.t()) :: Dagger.Env.t()
  def with_service_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withServiceInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Service output to be assigned in the environment
  """
  @spec with_service_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_service_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withServiceOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Create or update a binding of type Socket in the environment
  """
  @spec with_socket_input(t(), String.t(), Dagger.Socket.t(), String.t()) :: Dagger.Env.t()
  def with_socket_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withSocketInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", Dagger.ID.id!(value))
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declare a desired Socket output to be assigned in the environment
  """
  @spec with_socket_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_socket_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withSocketOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Provides a string input binding to the environment
  """
  @spec with_string_input(t(), String.t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_string_input(%__MODULE__{} = env, name, value, description) do
    query_builder =
      env.query_builder
      |> QB.select("withStringInput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("value", value)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Declares a desired string output binding
  """
  @spec with_string_output(t(), String.t(), String.t()) :: Dagger.Env.t()
  def with_string_output(%__MODULE__{} = env, name, description) do
    query_builder =
      env.query_builder
      |> QB.select("withStringOutput")
      |> QB.put_arg("name", name)
      |> QB.put_arg("description", description)

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Returns a new environment with the provided workspace
  """
  @spec with_workspace(t(), Dagger.Directory.t()) :: Dagger.Env.t()
  def with_workspace(%__MODULE__{} = env, workspace) do
    query_builder =
      env.query_builder
      |> QB.select("withWorkspace")
      |> QB.put_arg("workspace", Dagger.ID.id!(workspace))

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @doc """
  Returns a new environment without any outputs
  """
  @spec without_outputs(t()) :: Dagger.Env.t()
  def without_outputs(%__MODULE__{} = env) do
    query_builder =
      env.query_builder |> QB.select("withoutOutputs")

    %Dagger.Env{
      query_builder: query_builder,
      client: env.client
    }
  end

  @spec workspace(t()) :: Dagger.Directory.t()
  def workspace(%__MODULE__{} = env) do
    query_builder =
      env.query_builder |> QB.select("workspace")

    %Dagger.Directory{
      query_builder: query_builder,
      client: env.client
    }
  end
end

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

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