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

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

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

  @derive Dagger.ID

  defstruct [:query_builder, :client]

  @type t() :: %__MODULE__{}

  @doc """
  The match's end offset within the matched lines.
  """
  @spec end_(t()) :: {:ok, integer()} | {:error, term()}
  def end_(%__MODULE__{} = search_submatch) do
    query_builder =
      search_submatch.query_builder |> QB.select("end")

    Client.execute(search_submatch.client, query_builder)
  end

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

    Client.execute(search_submatch.client, query_builder)
  end

  @doc """
  The match's start offset within the matched lines.
  """
  @spec start(t()) :: {:ok, integer()} | {:error, term()}
  def start(%__MODULE__{} = search_submatch) do
    query_builder =
      search_submatch.query_builder |> QB.select("start")

    Client.execute(search_submatch.client, query_builder)
  end

  @doc """
  The matched text.
  """
  @spec text(t()) :: {:ok, String.t()} | {:error, term()}
  def text(%__MODULE__{} = search_submatch) do
    query_builder =
      search_submatch.query_builder |> QB.select("text")

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

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

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