# This file is auto-generated by alef — DO NOT EDIT.
# alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
# To regenerate: alef generate
# To verify freshness: alef verify --exit-code
# Issues & docs: https://github.com/kreuzberg-dev/alef
defmodule Kreuzberg.OcrElement do
  @moduledoc """
  A unified OCR element representing detected text with full metadata.

  This is the primary type for structured OCR output, preserving all information
  from both Tesseract and PaddleOCR backends.
  """

  @typedoc "A unified OCR element representing detected text with full metadata."
  @type t :: %__MODULE__{
          text: String.t() | nil,
          geometry: String.t() | nil,
          confidence: map(),
          level: String.t() | nil,
          rotation: map() | nil,
          page_number: non_neg_integer(),
          parent_id: String.t() | nil,
          backend_metadata: map()
        }

  defstruct text: nil,
            geometry: :rectangle,
            confidence: nil,
            level: :line,
            rotation: nil,
            page_number: 0,
            parent_id: nil,
            backend_metadata: %{}

  defimpl Jason.Encoder do
    @doc false
    def encode(value, opts) do
      value
      |> Map.from_struct()
      |> Enum.reject(fn {_k, v} -> v == nil end)
      |> Enum.into(%{})
      |> Jason.Encoder.encode(opts)
    end
  end
end
