"""Tests de l'état de configuration G3-B (profils/options résolus sans fichiers réels)."""

from __future__ import annotations

from pathlib import Path

from gui_v6.config_state import ConfigState, default_profile_key, list_profile_keys
from gui_v6.engine_bridge import EngineSettings


def test_to_engine_settings_defaults():
    settings = ConfigState().to_engine_settings(config_path=Path("/tmp/c.yml"))
    assert isinstance(settings, EngineSettings)
    assert settings.make_vector_redaction is False
    assert settings.also_make_raster_burn is True
    assert settings.use_local_ner is True
    assert settings.config_path == Path("/tmp/c.yml")


def test_to_engine_settings_custom():
    state = ConfigState(
        profile="oncologie",
        raster_burn=False,
        use_local_ner=False,
        enable_gliner=True,
        ogc_label="OCG",
    )
    settings = state.to_engine_settings()
    assert settings.also_make_raster_burn is False
    assert settings.use_local_ner is False
    assert settings.enable_gliner is True
    assert settings.profile == "oncologie"
    assert settings.ogc_label == "OCG"


def test_list_profile_keys_injected():
    keys = list_profile_keys(lister=lambda: {"b": {}, "a": {}})
    assert keys == ["a", "b"]


def test_list_profile_keys_failure_returns_empty():
    def boom():
        raise RuntimeError("pas de profils")

    assert list_profile_keys(lister=boom) == []


def test_default_profile_key_injected():
    assert default_profile_key(getter=lambda: "defaut") == "defaut"


def test_default_profile_key_failure_returns_none():
    def boom():
        raise RuntimeError("ko")

    assert default_profile_key(getter=boom) is None
