# This file generated by `dagger_codegen`. Please DO NOT EDIT.
defmodule Dagger.Label do
  @moduledoc """
  A simple key value object that represents a label.
  """

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

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

    Client.execute(label.client, query_builder)
  end

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

    Client.execute(label.client, query_builder)
  end

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

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

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

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