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_class_name_settings_not_editable():
    """All class_name settings should be hidden and non-editable."""
    settings = _load_settings()

    class_name_keys = [k for k in settings if k.endswith(".class_name")]
    assert class_name_keys, "Expected at least one class_name setting"

    for key in class_name_keys:
        value = settings[key]
        assert value.get("editable") is False, f"{key} should not be editable"
        assert value.get("visible") is False, f"{key} should not be visible"


def test_module_path_settings_not_editable():
    """All module_path settings should be hidden and non-editable."""
    settings = _load_settings()

    module_path_keys = [k for k in settings if k.endswith(".module_path")]
    assert module_path_keys, "Expected at least one module_path setting"

    for key in module_path_keys:
        value = settings[key]
        assert value.get("editable") is False, f"{key} should not be editable"
        assert value.get("visible") is False, f"{key} should not be visible"


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"
    )
