"""Snapshot tests for lexicon lookups via the search index.

Uses syrupy for snapshot comparison.  Pass --snapshot-update to regenerate.

These tests require a populated search-index database and morphology data.
If either is unavailable the tests skip gracefully.
"""

from __future__ import annotations

import pytest

pytestmark = pytest.mark.snapshot


def _make_engine():
    """Try to construct the LookupEngine.  Returns None if prerequisites
    are missing (no search-index DB, no morphology data)."""
    try:
        from accordance_parser.search_index import SearchIndex
        from accordance_parser.morphology import MorphologyDB
        from accordance_parser.lookup_engine import LookupEngine

        si = SearchIndex()
        morph = MorphologyDB()
        return LookupEngine(si, morph)
    except Exception:
        return None


_engine = _make_engine()


@pytest.mark.skipif(_engine is None, reason="Search index DB or morphology data not available")
def test_lookup_logos(snapshot):
    result = _engine.resolve("logos")
    lexicon_results = result.results_by_type.get("lexicon", [])
    first = lexicon_results[0] if lexicon_results else None
    assert repr(first)[:500] if first else "NO_RESULT" == snapshot


@pytest.mark.skipif(_engine is None, reason="Search index DB or morphology data not available")
def test_lookup_agape(snapshot):
    result = _engine.resolve("agape")
    lexicon_results = result.results_by_type.get("lexicon", [])
    first = lexicon_results[0] if lexicon_results else None
    assert repr(first)[:500] if first else "NO_RESULT" == snapshot
