# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.GeneratedCode do
  @moduledoc """
  The result of running an SDK's codegen.
  """

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

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

  @derive Dagger.ID

  defstruct [:query_builder, :client]

  @type t() :: %__MODULE__{}

  @doc """
  The directory containing the generated code.
  """
  @spec code(t()) :: Dagger.Directory.t()
  def code(%__MODULE__{} = generated_code) do
    query_builder =
      generated_code.query_builder |> QB.select("code")

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

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

    Client.execute(generated_code.client, query_builder)
  end

  @doc """
  List of paths to mark generated in version control (i.e. .gitattributes).
  """
  @spec vcs_generated_paths(t()) :: {:ok, [String.t()]} | {:error, term()}
  def vcs_generated_paths(%__MODULE__{} = generated_code) do
    query_builder =
      generated_code.query_builder |> QB.select("vcsGeneratedPaths")

    Client.execute(generated_code.client, query_builder)
  end

  @doc """
  List of paths to ignore in version control (i.e. .gitignore).
  """
  @spec vcs_ignored_paths(t()) :: {:ok, [String.t()]} | {:error, term()}
  def vcs_ignored_paths(%__MODULE__{} = generated_code) do
    query_builder =
      generated_code.query_builder |> QB.select("vcsIgnoredPaths")

    Client.execute(generated_code.client, query_builder)
  end

  @doc """
  Set the list of paths to mark generated in version control.
  """
  @spec with_vcs_generated_paths(t(), [String.t()]) :: Dagger.GeneratedCode.t()
  def with_vcs_generated_paths(%__MODULE__{} = generated_code, paths) do
    query_builder =
      generated_code.query_builder
      |> QB.select("withVCSGeneratedPaths")
      |> QB.put_arg("paths", paths)

    %Dagger.GeneratedCode{
      query_builder: query_builder,
      client: generated_code.client
    }
  end

  @doc """
  Set the list of paths to ignore in version control.
  """
  @spec with_vcs_ignored_paths(t(), [String.t()]) :: Dagger.GeneratedCode.t()
  def with_vcs_ignored_paths(%__MODULE__{} = generated_code, paths) do
    query_builder =
      generated_code.query_builder
      |> QB.select("withVCSIgnoredPaths")
      |> QB.put_arg("paths", paths)

    %Dagger.GeneratedCode{
      query_builder: query_builder,
      client: generated_code.client
    }
  end
end

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

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