"""Tests: Wiki → Skill Mapping (KarateRelevanz, RelevanzLevel)."""

from smw_mapper import (
    map_wiki_to_skill,
    parse_wiki_relevance_level,
)


def test_parse_wiki_relevance_level_accepted_range():
    assert parse_wiki_relevance_level("1") == 1
    assert parse_wiki_relevance_level("3") == 3
    assert parse_wiki_relevance_level("Level_2_-_foo") == 2


def test_parse_wiki_relevance_level_rejects():
    assert parse_wiki_relevance_level("") is None
    assert parse_wiki_relevance_level("4") is None
    assert parse_wiki_relevance_level("0") is None
    assert parse_wiki_relevance_level("text") is None


def test_map_wiki_to_skill_karate_and_level():
    out = map_wiki_to_skill(
        "Test_Skill",
        99,
        {
            "Summary": ["Kurztext"],
            "KarateRelevanz": ["''Wichtig'' für [[Kumite]]"],
            "RelevanzLevel": ["2"],
        },
    )
    assert out["name"] == "Test_Skill"
    assert out["description"] == "Kurztext"
    assert "Kumite" in out["karate_relevance"]
    assert out["relevance_level"] == 2
    assert out["warnings"] == []


def test_map_wiki_to_skill_synonym_props():
    out = map_wiki_to_skill("S", None, {"relevanzlevel": ["3"], "karaterelevanz": ["Nur Karate"]})
    assert out["relevance_level"] == 3
    assert out["karate_relevance"] == "Nur Karate"


def test_map_wiki_to_skill_invalid_level_warning():
    out = map_wiki_to_skill("S", None, {"RelevanzLevel": ["9"]})
    assert "relevance_level" not in out
    assert len(out["warnings"]) == 1
    assert "9" in out["warnings"][0]
