import importlib.util

import pytest


def test_import_ketju() -> None:
    import ketju  # noqa: F401


def test_import_ketju_rag_is_lightweight() -> None:
    # Importing ketju.rag should not require optional RAG backends.
    import ketju.rag  # noqa: F401


def test_rag_variants_require_extra_if_missing() -> None:
    import ketju.rag

    if importlib.util.find_spec("llama_index") is None:
        with pytest.raises(ModuleNotFoundError):
            _ = ketju.rag.SimplePdfRag
    else:
        assert ketju.rag.SimplePdfRag


def test_agent_module_requires_extra_if_missing() -> None:
    if importlib.util.find_spec("pydantic_ai") is None:
        with pytest.raises(ModuleNotFoundError):
            import ketju.agents  # noqa: F401
    else:
        import ketju.agents  # noqa: F401


def test_instrumentation_module_import_is_safe() -> None:
    import ketju.core.instrumentation  # noqa: F401


def test_instrumentation_call_is_noop_without_deps() -> None:
    from ketju.core.instrumentation import instrument_ketju

    res = instrument_ketju(
        service_name="test",
        enable_logfire=True,
        instrument_llamaindex=True,
        strict=False,
    )
    assert res is not None

