"""Session 78 — Catholic layperson scenario tests for Accordance Port.

Scenarios:
  S-L-13 — Parenting: Why Does God Allow Suffering?
  S-L-14 — Grief: Anniversary-of-Death Scripture Chain
  S-L-15 — Workplace: Sunday Rest and Fair Wages
  S-L-16 — Young Adult: Vocational Discernment
  S-L-17 — Small Group: Leading First-Time Beatitudes Study
  S-L-18 — Reversion: "Coming Home" After 15 Years
  S-L-19 — Cultural Tradition: Dia de los Muertos / All Souls
  S-L-20 — Seniors: Legacy Scripture Journal for Grandchildren
  S-L-21 — Environmentalism: Laudato Si Scripture Foundation
  S-L-22 — Social Media: Defending the Faith
  S-L-23 — Health/Chronic Illness: Redemptive Suffering
  S-L-24 — Dating/Engagement: Marriage Biblical Foundation

All tests are skippable if required modules/network are not available.
Tests are concrete, callable, and ≤15 lines each.
"""
from __future__ import annotations

import pytest


# =============================================================================
# IMPORT GUARDS — import everything with try/except, following project conventions
# =============================================================================

# --- Bible API (local cache for KJV, network for others) ---
try:
    from accordance_parser.bible_api import get_verse
    _has_bible_api = True
except Exception:
    _has_bible_api = False

# --- Morphology (local) ---
try:
    from accordance_parser.morphology import get_morphology
    _has_morphology = True
except Exception:
    _has_morphology = False

# --- Acc2 tools (find_ot_quotations, find_parallel_passages) ---
try:
    from accordance_services.tools.acc2 import find_ot_quotations, find_parallel_passages
    _has_acc2 = True
except Exception:
    _has_acc2 = False

# --- Search tools (search_verses_by_term) ---
try:
    from accordance_services.tools.search import search_verses_by_term
    _has_search_tools = True
except Exception:
    _has_search_tools = False

# --- Strong's search tools ---
try:
    _has_strongs_tools = True
except Exception:
    _has_strongs_tools = False

# --- MCP server tools (depends on FastMCP/uvicorn) ---
_has_mcp = False
try:
    from accordance_mcp_server import (
        daily_mass_readings,
        get_strongs_for_verse,
        study_strongs_number,
        word_study,
        search_commentaries_for_topic,
        search_commentaries,
        search_dictionary_content,
        compare_translations,
        compare_catholic_translations,
        find_cross_references,
        search_all,
        search_commentary_text,
        thematic_study,
        compare_definitions,
        outline_book,
    )
    _has_mcp = True
except Exception:
    pass


# =============================================================================
# NETWORK DETECTION
# =============================================================================

_has_network = False
try:
    from accordance_parser.bible_api import get_verse as _gv
    r = _gv("Genesis 1:1", "KJV")
    if r and r.text:
        _has_network = True
except Exception:
    pass


# =============================================================================
# HELPERS
# =============================================================================

def _str_ok(text: str) -> bool:
    """Return True if text is a non-empty string with no Python traceback."""
    if not isinstance(text, str):
        return False
    if not text.strip():
        return False
    if "Traceback (most recent call last)" in text:
        return False
    return True


# =============================================================================
# S-L-13: CATHOLIC PARENTING — "Why Does God Allow Suffering?"
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestParentingSuffering:
    """S-L-13: Parenting — suffering, Job, Jesus wept, Revelation comfort chain."""

    def test_fts5_search_suffering(self):
        """search_all('suffering', max_results=10) should return cross-module results."""
        result = search_all("suffering", max_results=10)
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_job_1_21(self):
        """Job 1:21 NABRE — 'the Lord gave and has taken away'."""
        result = get_verse("Job 1:21", "NABRE")
        assert result is not None and result.text
        assert "taken" in result.text.lower() or "gave" in result.text.lower()

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_job_38_4_7(self):
        """Job 38:4-7 NABRE — God's whirlwind answer."""
        result = get_verse("Job 38:4-7", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["foundation", "earth", "morning", "stars"])

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_john_11_33_36(self):
        """John 11:33-36 NABRE — 'Jesus wept'."""
        result = get_verse("John 11:33-36", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["weeping", "wept", "perturbed", "deeply", "troubled", "jesus"])

    def test_word_study_john_11_35_wept(self):
        """word_study on John 11:35 (KJV) — 'wept' G1145."""
        result = word_study("John 11:35", max_words=5)
        assert _str_ok(result)
        assert any(
            phrase in result.lower()
            for phrase in ("word study", "strong", "g1145", "wept", "john")
        ) or "unavailable" in result.lower()

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_revelation_21_4(self):
        """Revelation 21:4 NABRE — 'wipe every tear'."""
        result = get_verse("Revelation 21:4", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["tear", "death", "mourning", "pain"])


# =============================================================================
# S-L-14: CATHOLIC GRIEF — Anniversary-of-Death Scripture Chain
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestGriefAnniversary:
    """S-L-14: Grief — comfort word families, Psalm 34:18, Wisdom 3, commentary."""

    def test_thematic_study_comfort(self):
        """thematic_study('comfort') should return Strong's word families."""
        result = thematic_study("comfort")
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_psalm_34_18(self):
        """Psalm 34:18 NABRE — 'Lord is close to the brokenhearted'."""
        result = get_verse("Psalm 34:18", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["righteous", "lord", "cry", "afflictions", "rescues", "hears"])

    def test_compare_catholic_psalm_34_18(self):
        """compare_catholic_translations('Psalm 34:18') should return NABRE/NRSVCE/DRB."""
        result = compare_catholic_translations("Psalm 34:18")
        assert _str_ok(result)
        assert any(label in result for label in ("NABRE", "NRSVCE", "DRB"))

    def test_find_cross_refs_psalm_34_18(self):
        """find_cross_references('Psalm 34:18') should not crash."""
        result = find_cross_references("Psalm 34:18")
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_1thess_4_13_14(self):
        """1 Thessalonians 4:13-14 NABRE — hope beyond grief."""
        result = get_verse("1 Thessalonians 4:13-14", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["grieve", "hope", "asleep", "died", "jesus"])

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_wisdom_3_1_4(self):
        """Wisdom 3:1-4 NABRE — deuterocanonical funeral text."""
        result = get_verse("Wisdom 3:1-4", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["soul", "hand", "peace", "hope", "immortality", "torment"])

    def test_search_commentary_resurrection_hope(self):
        """search_commentary_text('resurrection hope', max_results=5) should not crash."""
        result = search_commentary_text("resurrection hope", max_results=5)
        assert isinstance(result, str)
        assert len(result) > 0


# =============================================================================
# S-L-15: CATHOLIC WORKPLACE — Sunday Rest and Fair Wages
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestWorkplaceEthics:
    """S-L-15: Workplace — Sabbath rest, fair wages, James 5:4."""

    def test_search_all_sabbath_rest(self):
        """search_all('Sabbath rest', max_results=10) should return results."""
        result = search_all("Sabbath rest", max_results=10)
        assert isinstance(result, str)
        assert len(result) > 0

    def test_compare_translations_exodus_20_8_10(self):
        """compare_translations on Exodus 20:8-10 should show multiple translations."""
        result = compare_translations("Exodus 20:8-10", "NABRE,ESV,NIV,KJV")
        assert _str_ok(result)
        assert any(label in result for label in ("NABRE", "ESV", "NIV", "KJV"))

    def test_strongs_exodus_20_8(self):
        """get_strongs_for_verse on Exodus 20:8 should return H2142, H7676."""
        result = get_strongs_for_verse("Exodus 20:8")
        assert _str_ok(result)
        assert "[" in result or "H" in result or "No Strong" in result

    def test_study_H7676_sabbath(self):
        """study_strongs_number('H7676') should return Sabbath definition."""
        result = study_strongs_number("H7676")
        assert _str_ok(result)
        assert "H7676" in result or "7676" in result or "def" in result.lower()

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_deut_24_14_15(self):
        """Deuteronomy 24:14-15 NABRE — fair wages."""
        result = get_verse("Deuteronomy 24:14-15", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["wages", "hire", "poor", "sun"])

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_james_5_4(self):
        """James 5:4 NABRE — withheld wages cry out."""
        result = get_verse("James 5:4", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["wages", "cry", "harvesters", "fields"])


# =============================================================================
# S-L-16: CATHOLIC YOUNG ADULT — Vocational Discernment
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestVocationalDiscernment:
    """S-L-16: Vocational discernment — Genesis 2, Matthew 19, 1 Cor 7, Ephesians 5."""

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_genesis_2_18_24(self):
        """Genesis 2:18-24 NABRE — creation of marriage."""
        result = get_verse("Genesis 2:18-24", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["helper", "rib", "bone", "flesh", "wife"])

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_matthew_19_10_12(self):
        """Matthew 19:10-12 NABRE — celibacy for the kingdom."""
        result = get_verse("Matthew 19:10-12", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["marry", "disciples", "wife", "eunuch", "kingdom", "accept"])

    def test_compare_catholic_matthew_19_12(self):
        """compare_catholic_translations('Matthew 19:12') should show Catholic versions."""
        result = compare_catholic_translations("Matthew 19:12")
        assert _str_ok(result)
        assert any(label in result for label in ("NABRE", "NRSVCE", "DRB"))

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_1cor_7_32_35(self):
        """1 Corinthians 7:32-35 NABRE — Paul on the unmarried."""
        result = get_verse("1 Corinthians 7:32-35", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["unmarried", "anxiety", "lord", "married"])

    def test_search_commentaries_1cor_7_32(self):
        """search_commentaries('1 Corinthians 7:32') should return commentary."""
        result = search_commentaries("1 Corinthians 7:32")
        assert isinstance(result, str)
        assert len(result) > 0

    def test_word_study_1cor_7_7_gift(self):
        """word_study on 1 Cor 7:7 (KJV) — 'gift' G5486/charisma."""
        result = word_study("1 Corinthians 7:7", max_words=8)
        assert _str_ok(result)
        assert any(
            phrase in result.lower()
            for phrase in ("word study", "strong", "g5486", "gift", "charisma")
        ) or "unavailable" in result.lower()

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_ephesians_5_25_32(self):
        """Ephesians 5:25-32 NABRE — marriage as mystery."""
        result = get_verse("Ephesians 5:25-32", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["love", "church", "wife", "mystery", "flesh"])


# =============================================================================
# S-L-17: CATHOLIC SMALL GROUP — Leading First-Time Beatitudes Study
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestSmallGroupBeatitudes:
    """S-L-17: Small group — Beatitudes study with morphology, word study, OT quotations."""

    def test_outline_book_matthew(self):
        """outline_book('Matthew') should return chapter overview."""
        result = outline_book("Matthew")
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_matthew_5_3_12(self):
        """Matthew 5:3-12 NABRE — the Beatitudes."""
        result = get_verse("Matthew 5:3-12", "NABRE")
        assert result is not None and result.text
        assert "blessed" in result.text.lower() or "kingdom" in result.text.lower()

    def test_word_study_matthew_5_3_poor_in_spirit(self):
        """word_study on Matthew 5:3 (KJV) — 'poor in spirit' G4434/ptochos."""
        result = word_study("Matthew 5:3", max_words=8)
        assert _str_ok(result)
        assert any(
            phrase in result.lower()
            for phrase in ("word study", "strong", "g4434", "poor", "spirit")
        ) or "unavailable" in result.lower()

    @pytest.mark.skipif(not _has_morphology, reason="Morphology module not available")
    def test_morphology_matthew_5_3(self):
        """get_morphology('Matthew 5:3') should return grammatical parsing."""
        result = get_morphology("Matthew 5:3")
        assert result is not None
        assert len(result) > 0

    def test_search_dictionary_content_poor_in_spirit(self):
        """search_dictionary_content('poor in spirit', max_results=10) should not crash."""
        result = search_dictionary_content("poor in spirit", max_results=10)
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_search_tools, reason="Search tools not importable")
    def test_search_verses_by_term_blessed_are(self):
        """search_verses_by_term('blessed are', max_results=15) should find Beatitudes."""
        result = search_verses_by_term("blessed are", max_results=15)
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_acc2, reason="acc2 tools not importable")
    def test_find_ot_quotations_matthew_5_5(self):
        """find_ot_quotations('Matthew 5:5') should find Psalm 37:11 (blessed meek)."""
        result = find_ot_quotations("Matthew 5:5")
        assert isinstance(result, str)
        assert len(result) > 0

    def test_search_commentaries_matthew_5_3(self):
        """search_commentaries('Matthew 5:3') should return commentary entries."""
        result = search_commentaries("Matthew 5:3")
        assert isinstance(result, str)
        assert len(result) > 0


# =============================================================================
# S-L-18: CATHOLIC REVERSION — "Coming Home" After 15 Years
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestReversionComingHome:
    """S-L-18: Reversion — papacy, Petros/petra, keys of the kingdom, forgiveness, Mary."""

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_matthew_16_18_19(self):
        """Matthew 16:18-19 NABRE — Peter as rock, keys of the kingdom."""
        result = get_verse("Matthew 16:18-19", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["rock", "church", "keys", "kingdom"])

    def test_study_G4074_petros(self):
        """study_strongs_number('G4074') should return Petros/petra distinction."""
        result = study_strongs_number("G4074")
        assert _str_ok(result)
        assert "G4074" in result or "4074" in result or "def" in result.lower()

    def test_search_commentaries_keys_of_kingdom(self):
        """search_commentaries_for_topic('keys of the kingdom', max_results=8) should not crash."""
        result = search_commentaries_for_topic("keys of the kingdom", max_results=8)
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_john_20_21_23(self):
        """John 20:21-23 NABRE — forgiveness of sins authority."""
        result = get_verse("John 20:21-23", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["peace", "father", "send", "spirit", "forgive", "retain"])

    @pytest.mark.skipif(not _has_acc2, reason="acc2 tools not importable")
    def test_find_parallel_passages_john_20_23(self):
        """find_parallel_passages('John 20:23') should find Gospel parallels."""
        result = find_parallel_passages("John 20:23")
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_luke_1_41_42(self):
        """Luke 1:41-42 NABRE — Elizabeth: 'blessed among women'."""
        result = get_verse("Luke 1:41-42", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["blessed", "women", "elizabeth", "fruit"])

    def test_compare_catholic_luke_1_42(self):
        """compare_catholic_translations('Luke 1:42') should show Catholic versions."""
        result = compare_catholic_translations("Luke 1:42")
        assert _str_ok(result)
        assert any(label in result for label in ("NABRE", "NRSVCE", "DRB"))


# =============================================================================
# S-L-19: CATHOLIC CULTURAL TRADITION — Dia de los Muertos / All Souls
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestDiaDeLosMuertos:
    """S-L-19: Dia de los Muertos / All Souls — daily readings, Maccabees, Wisdom, bilingual."""

    def test_daily_mass_readings_all_souls(self):
        """daily_mass_readings('2026-11-02') should return All Souls Day readings."""
        result = daily_mass_readings("2026-11-02")
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_2macc_12_44_46(self):
        """2 Maccabees 12:44-46 NABRE — prayer for the dead."""
        result = get_verse("2 Maccabees 12:44-46", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["pray", "dead", "resurrection", "atonement", "sin"])

    def test_compare_catholic_2macc_12_45(self):
        """compare_catholic_translations('2 Maccabees 12:45') should show versions."""
        result = compare_catholic_translations("2 Maccabees 12:45")
        assert _str_ok(result)
        assert any(label in result for label in ("NABRE", "NRSVCE", "DRB"))

    def test_compare_translations_john_6_40_bilingual(self):
        """compare_translations('John 6:40', 'NABRE,LBLA,NBLH') — bilingual Spanish."""
        result = compare_translations("John 6:40", "NABRE,LBLA,NBLH")
        assert isinstance(result, str)
        assert len(result) > 0

    def test_search_all_eternal_rest(self):
        """search_all('eternal rest', max_results=10) should return results."""
        result = search_all("eternal rest", max_results=10)
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_wisdom_4_7_9(self):
        """Wisdom 4:7-9 NABRE — the righteous at rest."""
        result = get_verse("Wisdom 4:7-9", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["righteous", "rest", "age", "understanding"])

    def test_find_cross_refs_wisdom_4_7(self):
        """find_cross_references('Wisdom 4:7') should not crash."""
        result = find_cross_references("Wisdom 4:7")
        assert isinstance(result, str)
        assert len(result) > 0


# =============================================================================
# S-L-20: CATHOLIC SENIORS — Legacy Scripture Journal for Grandchildren
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestLegacyJournal:
    """S-L-20: Seniors — Proverbs outline, generation word families, Psalm 71, 2 Tim 1:5."""

    def test_outline_book_proverbs(self):
        """outline_book('Proverbs') should return chapter overview."""
        result = outline_book("Proverbs")
        assert isinstance(result, str)
        assert len(result) > 0

    def test_thematic_study_generation(self):
        """thematic_study('generation') should return dor/genea word families."""
        result = thematic_study("generation")
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_psalm_71_17_18(self):
        """Psalm 71:17-18 NABRE — 'now that I am old and gray'."""
        result = get_verse("Psalm 71:17-18", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["old", "gray", "age", "youth", "generation"])

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_proverbs_17_6(self):
        """Proverbs 17:6 NABRE — 'grandchildren are the crown of the aged'."""
        result = get_verse("Proverbs 17:6", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["grandchildren", "crown", "aged", "fathers", "children"])

    def test_word_study_proverbs_17_6_crown(self):
        """word_study on Proverbs 17:6 (KJV) — 'crown' H5850/atarah."""
        result = word_study("Proverbs 17:6", max_words=8)
        assert _str_ok(result)
        assert any(
            phrase in result.lower()
            for phrase in ("word study", "strong", "h5850", "crown")
        ) or "unavailable" in result.lower()

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_2timothy_1_5(self):
        """2 Timothy 1:5 NABRE — Lois and Eunice, faith through generations."""
        result = get_verse("2 Timothy 1:5", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["faith", "lois", "eunice", "grandmother", "mother"])

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_deut_4_9(self):
        """Deuteronomy 4:9 NABRE — 'teach your children's children'."""
        result = get_verse("Deuteronomy 4:9", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["teach", "children", "generation", "forget"])

    def test_search_commentary_generation_faith(self):
        """search_commentary_text('generation faith grandchildren', max_results=5) should not crash."""
        result = search_commentary_text("generation faith grandchildren", max_results=5)
        assert isinstance(result, str)
        assert len(result) > 0


# =============================================================================
# S-L-21: CATHOLIC ENVIRONMENTALISM — Laudato Si Scripture Foundation
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestLaudatoSiEnvironment:
    """S-L-21: Laudato Si — stewardship, dominion, creation groaning, Daniel canticle."""

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_genesis_1_26_31(self):
        """Genesis 1:26-31 NABRE — dominion and stewardship."""
        result = get_verse("Genesis 1:26-31", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["dominion", "image", "earth", "creeping"])

    def test_word_study_genesis_1_28_dominion_subdue(self):
        """word_study on Genesis 1:28 (KJV) — 'dominion' H7287, 'subdue' H3533."""
        result = word_study("Genesis 1:28", max_words=10)
        assert _str_ok(result)
        assert any(
            phrase in result.lower()
            for phrase in ("word study", "strong", "h7287", "h3533", "dominion")
        ) or "unavailable" in result.lower()

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_psalm_24_1_2(self):
        """Psalm 24:1-2 NABRE — 'earth is the Lord's'."""
        result = get_verse("Psalm 24:1-2", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["earth", "lord", "world", "found"])

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_romans_8_19_22(self):
        """Romans 8:19-22 NABRE — creation groaning."""
        result = get_verse("Romans 8:19-22", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["creation", "groan", "bondage", "decay", "glory"])

    def test_search_commentaries_creation_groaning(self):
        """search_commentaries_for_topic('creation groaning', max_results=8) should not crash."""
        result = search_commentaries_for_topic("creation groaning", max_results=8)
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_daniel_3_57_82(self):
        """Daniel 3:57-82 NABRE — Canticle of the Three Young Men."""
        result = get_verse("Daniel 3:57-82", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["bless", "lord", "angels", "heavens"])

    def test_search_all_bless_the_lord_creation(self):
        """search_all('bless the Lord creation', max_results=10) should return results."""
        result = search_all("bless the Lord creation", max_results=10)
        assert isinstance(result, str)
        assert len(result) > 0


# =============================================================================
# S-L-22: CATHOLIC SOCIAL MEDIA — Defending the Faith
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestSocialMediaDefense:
    """S-L-22: Social media defense — worship God alone, Magnificat, proskyneo, queen mother."""

    def test_search_all_worship_god_alone(self):
        """search_all('worship God alone', max_results=10) should return results."""
        result = search_all("worship God alone", max_results=10)
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_luke_1_48(self):
        """Luke 1:48 NABRE — 'all generations will call me blessed'."""
        result = get_verse("Luke 1:48", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["blessed", "generation", "magnify", "handmaid"])

    @pytest.mark.skipif(not _has_morphology, reason="Morphology module not available")
    def test_morphology_luke_1_48(self):
        """get_morphology('Luke 1:48') should return Magnificat grammar."""
        result = get_morphology("Luke 1:48")
        assert result is not None
        assert len(result) > 0

    def test_compare_definitions_G4352(self):
        """compare_definitions('G4352') — proskyneo (worship/bow down)."""
        result = compare_definitions("G4352")
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_1kings_2_19(self):
        """1 Kings 2:19 NABRE — Bathsheba honored, queen mother typology."""
        result = get_verse("1 Kings 2:19", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["bathsheba", "mother", "throne", "king", "queen"])

    def test_find_cross_refs_1kings_2_19(self):
        """find_cross_references('1 Kings 2:19') should not crash."""
        result = find_cross_references("1 Kings 2:19")
        assert isinstance(result, str)
        assert len(result) > 0

    def test_search_commentaries_queen_mother(self):
        """search_commentaries_for_topic('queen mother intercession', max_results=5) should not crash."""
        result = search_commentaries_for_topic("queen mother intercession", max_results=5)
        assert isinstance(result, str)
        assert len(result) > 0


# =============================================================================
# S-L-23: CATHOLIC HEALTH/CHRONIC ILLNESS — Redemptive Suffering
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestChronicIllnessSuffering:
    """S-L-23: Chronic illness — thorn in the flesh, grace, Colossians 1:24, redemptive suffering."""

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_2cor_12_7_10(self):
        """2 Corinthians 12:7-10 NABRE — 'thorn in the flesh'."""
        result = get_verse("2 Corinthians 12:7-10", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["thorn", "flesh", "grace", "weakness", "boast"])

    def test_word_study_2cor_12_7_thorn_grace(self):
        """word_study on 2 Cor 12:7 (KJV) — 'thorn' G4647, 'buffet' G2852, 'grace' G5485."""
        result = word_study("2 Corinthians 12:7", max_words=15)
        assert _str_ok(result)
        assert any(
            phrase in result.lower()
            for phrase in ("word study", "strong", "g4647", "g2852", "g5485")
        ) or "unavailable" in result.lower()

    @pytest.mark.skipif(not _has_morphology, reason="Morphology module not available")
    def test_morphology_2cor_12_9(self):
        """get_morphology('2 Corinthians 12:9') — 'power made perfect in weakness'."""
        result = get_morphology("2 Corinthians 12:9")
        assert result is not None
        assert len(result) > 0

    def test_search_commentaries_thorn_in_flesh(self):
        """search_commentaries_for_topic('thorn in the flesh', max_results=8) should not crash."""
        result = search_commentaries_for_topic("thorn in the flesh", max_results=8)
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_colossians_1_24(self):
        """Colossians 1:24 NABRE — 'fill up what is lacking in Christ's afflictions'."""
        result = get_verse("Colossians 1:24", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["suffering", "affliction", "lacking", "body", "church"])

    def test_search_commentary_redemptive_suffering(self):
        """search_commentary_text('redemptive suffering colossians 1:24', max_results=5) should not crash."""
        result = search_commentary_text("redemptive suffering colossians 1:24", max_results=5)
        assert isinstance(result, str)
        assert len(result) > 0

    def test_search_commentaries_healing_faith(self):
        """search_commentaries_for_topic('healing faith suffering', max_results=5) should not crash."""
        result = search_commentaries_for_topic("healing faith suffering", max_results=5)
        assert isinstance(result, str)
        assert len(result) > 0


# =============================================================================
# S-L-24: CATHOLIC DATING/ENGAGEMENT — Marriage Biblical Foundation
# =============================================================================

@pytest.mark.skipif(not _has_mcp, reason="MCP server not importable")
class TestDatingMarriagePrep:
    """S-L-24: Dating/engagement — Genesis 2:24, cross-refs, Ephesians 5, 1 Cor 6-7."""

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_genesis_2_23_24(self):
        """Genesis 2:23-24 NABRE — 'bone of my bones... one flesh'."""
        result = get_verse("Genesis 2:23-24", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["bone", "flesh", "woman", "wife", "leave"])

    def test_strongs_genesis_2_24(self):
        """get_strongs_for_verse on Genesis 2:24 — H5800 (leave), H1692 (cling), H1320 (flesh)."""
        result = get_strongs_for_verse("Genesis 2:24")
        assert _str_ok(result)
        assert "[" in result or "H" in result or "No Strong" in result

    def test_find_cross_refs_genesis_2_24(self):
        """find_cross_references('Genesis 2:24') should find NT quotations."""
        result = find_cross_references("Genesis 2:24")
        assert isinstance(result, str)
        assert len(result) > 0

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_ephesians_5_21_33(self):
        """Ephesians 5:21-33 NABRE — the great mystery (marriage/Christ/church)."""
        result = get_verse("Ephesians 5:21-33", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["christ", "subordinate", "reverence", "wives", "husbands", "love", "church", "mystery"])

    def test_word_study_ephesians_5_25_love_gave(self):
        """word_study on Ephesians 5:25 (KJV) — 'love' G25/agapao, 'gave' G3860/paradidomi."""
        result = word_study("Ephesians 5:25", max_words=10)
        assert _str_ok(result)
        assert any(
            phrase in result.lower()
            for phrase in ("word study", "strong", "g25", "g3860", "love")
        ) or "unavailable" in result.lower()

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_1cor_6_19_20(self):
        """1 Corinthians 6:19-20 NABRE — 'body is temple'."""
        result = get_verse("1 Corinthians 6:19-20", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["temple", "body", "holy", "spirit", "glorify"])

    @pytest.mark.skipif(not _has_network, reason="Requires network for NABRE")
    def test_nabre_1cor_7_3_5(self):
        """1 Corinthians 7:3-5 NABRE — mutual consent / NFP basis."""
        result = get_verse("1 Corinthians 7:3-5", "NABRE")
        assert result is not None and result.text
        assert any(w in result.text.lower() for w in ["husband", "wife", "duty", "deprive", "prayer", "tempt"])

    def test_search_commentaries_ephesians_5_31(self):
        """search_commentaries('Ephesians 5:31') — Paul quotes Genesis 2:24."""
        result = search_commentaries("Ephesians 5:31")
        assert isinstance(result, str)
        assert len(result) > 0
