import json
from pathlib import Path

SETTINGS_PATH = Path("src/local_deep_research/defaults/default_settings.json")


def _load_settings():
    with open(SETTINGS_PATH) as f:
        return json.load(f)


def test_no_module_path_or_class_name_in_defaults():
    """module_path and class_name should NOT be in settings JSON.

    These are now in the hardcoded engine registry (engine_registry.py),
    not in the user-configurable settings database.
    """
    settings = _load_settings()

    for key in settings:
        assert not key.endswith(".module_path"), (
            f"{key} should not be in default_settings.json — "
            "use engine_registry.py instead"
        )
        assert not key.endswith(".class_name"), (
            f"{key} should not be in default_settings.json — "
            "use engine_registry.py instead"
        )
        assert not key.endswith(".full_search_module"), (
            f"{key} should not be in default_settings.json — "
            "use engine_registry.py instead"
        )
        assert not key.endswith(".full_search_class"), (
            f"{key} should not be in default_settings.json — "
            "use engine_registry.py instead"
        )


def test_user_facing_settings_remain_editable():
    """Regular user-facing settings should still be editable."""
    settings = _load_settings()

    user_facing_suffixes = (".enabled", ".api_key", ".max_results")

    found = False
    for key, value in settings.items():
        if any(key.endswith(suffix) for suffix in user_facing_suffixes):
            if isinstance(value, dict) and "editable" in value:
                assert value["editable"] is not False, (
                    f"{key} is a user-facing setting but is marked non-editable"
                )
                found = True

    assert found, (
        "Expected at least one user-facing editable setting to validate"
    )
