# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.SourceMap do
  @moduledoc """
  Source location information.
  """

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

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

  @derive Dagger.ID

  defstruct [:query_builder, :client]

  @type t() :: %__MODULE__{}

  @doc """
  The column number within the line.
  """
  @spec column(t()) :: {:ok, integer()} | {:error, term()}
  def column(%__MODULE__{} = source_map) do
    query_builder =
      source_map.query_builder |> QB.select("column")

    Client.execute(source_map.client, query_builder)
  end

  @doc """
  The filename from the module source.
  """
  @spec filename(t()) :: {:ok, String.t()} | {:error, term()}
  def filename(%__MODULE__{} = source_map) do
    query_builder =
      source_map.query_builder |> QB.select("filename")

    Client.execute(source_map.client, query_builder)
  end

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

    Client.execute(source_map.client, query_builder)
  end

  @doc """
  The line number within the filename.
  """
  @spec line(t()) :: {:ok, integer()} | {:error, term()}
  def line(%__MODULE__{} = source_map) do
    query_builder =
      source_map.query_builder |> QB.select("line")

    Client.execute(source_map.client, query_builder)
  end

  @doc """
  The module dependency this was declared in.
  """
  @spec module(t()) :: {:ok, String.t()} | {:error, term()}
  def module(%__MODULE__{} = source_map) do
    query_builder =
      source_map.query_builder |> QB.select("module")

    Client.execute(source_map.client, query_builder)
  end

  @doc """
  The URL to the file, if any. This can be used to link to the source map in the browser.
  """
  @spec url(t()) :: {:ok, String.t()} | {:error, term()}
  def url(%__MODULE__{} = source_map) do
    query_builder =
      source_map.query_builder |> QB.select("url")

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

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

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