# 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.TextMetadata do
  @moduledoc """
  Text/Markdown metadata.

  Extracted from plain text and Markdown files. Includes word counts and,
  for Markdown, structural elements like headers and links.
  """

  @typedoc "Text/Markdown metadata."
  @type t :: %__MODULE__{
          line_count: non_neg_integer(),
          word_count: non_neg_integer(),
          character_count: non_neg_integer(),
          headers: [String.t()] | nil,
          links: [[String.t()]] | nil,
          code_blocks: [[String.t()]] | nil
        }

  defstruct line_count: 0,
            word_count: 0,
            character_count: 0,
            headers: nil,
            links: nil,
            code_blocks: nil

  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
