"""
Document-level parsers.

`Parser` is the engine-agnostic ABC for converting a source file into a
`ParseResult`, which carries the `DoclingDocument` — the canonical in-memory
document model (see core/README.md) — on `.document`.
`DoclingParser` is the abstract docling layer; the docling configuration is a
type, not a flag: `TunedFinancialParser` (canonical default) and
`LegacyDoclingParser` (docling's default backend and PdfPipelineOptions, with
OCR off where docling defaults it on). Use `parser_for_preset` to pick one.

Table-only engines live behind a separate `TableExtractor` Protocol in
`core.extractors`; the active one is `SetOfMarkExtractor`. The two paths do not
compose at this layer. `quber.core.fusion` matches the extracted tables to the
parse's tables and grafts them into a unified `DoclingDocument`.
"""

from typing import TYPE_CHECKING, Any

from quber.core.parsers.base import Parser
from quber.core.parsers.mock import MockParser
from quber.core.parsers.result import (
    PageParse,
    PageScore,
    ParsedCell,
    ParseResult,
    TableProvenance,
)

if TYPE_CHECKING:
    from quber.core.parsers.docling_parser import (
        PARSERS_BY_PRESET,
        DoclingParser,
        LegacyDoclingParser,
        TunedFinancialParser,
        parser_for_preset,
    )

# The docling engine classes need the full `docling` package (the GPU extra).
# The fuse cloud job imports this package only for `ParseResult` and must run
# on the CPU image, so the engine names resolve lazily on first access
# instead of at package import.
ENGINE_EXPORTS = (
    "PARSERS_BY_PRESET",
    "DoclingParser",
    "LegacyDoclingParser",
    "TunedFinancialParser",
    "parser_for_preset",
)


def __getattr__(name: str) -> Any:
    if name in ENGINE_EXPORTS:
        from quber.core.parsers import docling_parser

        return getattr(docling_parser, name)
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


__all__ = [
    "PARSERS_BY_PRESET",
    "DoclingParser",
    "LegacyDoclingParser",
    "MockParser",
    "PageParse",
    "PageScore",
    "ParseResult",
    "ParsedCell",
    "Parser",
    "TableProvenance",
    "TunedFinancialParser",
    "parser_for_preset",
]
