import pytest

from backend.app.services.ml.tag_name import normalize


@pytest.mark.parametrize(
    "raw, expected",
    [
        # Rule 4: underscores -> spaces; rule 7: title case
        ("light_purple_hair", "Light Purple Hair"),
        ("no_pants", "No Pants"),
        ("year_2005", "Year 2005"),
        # Single-word still title-cased
        ("sword", "Sword"),
        # Rule 3: drop trailing _(disambiguator)
        ("uchiha_sasuke_(naruto)", "Uchiha Sasuke"),
        ("apple_(fruit)", "Apple"),
        ("kirby_(series)", "Kirby"),
        # Repeated trailing disambig blocks
        ("foo_(bar)_(baz)", "Foo"),
        # Rule 1: leading junk chars
        ("#unicus_(idolmaster)", "Unicus"),
        (".52_gal_(splatoon)", "52 Gal"),
        ("+_+_smile_(emote)", "Smile"),
        # Rule 5: space after colon
        ("nier:automata", "Nier: Automata"),
        # Already-spaced colon left alone
        ("nier: automata", "Nier: Automata"),
        # Rule 6: hyphens preserved
        ("1000-nen_ikiteru_(vocaloid)", "1000-nen Ikiteru"),
        ("well-known_face", "Well-known Face"),
        # Rule 2: wrapping quotes
        ('"pile_em_up"_(genshin_impact)', "Pile Em Up"),
        ("'foo_bar'", "Foo Bar"),
        # Rule 8: emoticons -> None
        (":/", None),
        (";)", None),
        ("+_+", None),
        ("^_^", None),
        # Empty / whitespace-only
        ("", None),
        ("   ", None),
        ("___", None),
        # Apostrophe inside word — preserved, not title-cased
        ("it's_okay", "It's Okay"),
        # Digit-only still surfaces (year tags)
        ("2005", "2005"),
        # Multi-space collapse
        ("foo___bar", "Foo Bar"),
    ],
)
def test_normalize(raw, expected):
    assert normalize(raw) == expected
