# 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.Metadata do
  @moduledoc """
  Extraction result metadata.

  Contains common fields applicable to all formats, format-specific metadata
  via a discriminated union, and additional custom fields from postprocessors.
  """

  @typedoc "Extraction result metadata."
  @type t :: %__MODULE__{
          title: String.t() | nil,
          subject: String.t() | nil,
          authors: [String.t()] | nil,
          keywords: [String.t()] | nil,
          language: String.t() | nil,
          created_at: String.t() | nil,
          modified_at: String.t() | nil,
          created_by: String.t() | nil,
          modified_by: String.t() | nil,
          pages: map() | nil,
          format: String.t() | nil | nil,
          image_preprocessing: map() | nil,
          json_schema: String.t() | nil,
          error: map() | nil,
          extraction_duration_ms: non_neg_integer() | nil,
          category: String.t() | nil,
          tags: [String.t()] | nil,
          document_version: String.t() | nil,
          abstract_text: String.t() | nil,
          output_format: String.t() | nil,
          ocr_used: boolean(),
          additional: map()
        }

  defstruct title: nil,
            subject: nil,
            authors: nil,
            keywords: nil,
            language: nil,
            created_at: nil,
            modified_at: nil,
            created_by: nil,
            modified_by: nil,
            pages: nil,
            format: nil,
            image_preprocessing: nil,
            json_schema: nil,
            error: nil,
            extraction_duration_ms: nil,
            category: nil,
            tags: nil,
            document_version: nil,
            abstract_text: nil,
            output_format: nil,
            ocr_used: false,
            additional: %{}

  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
