"""Emotion-tag extraction: strip tag, map to mood stem + protocol emotion."""
import tts


def test_split_known_tag():
    assert tts.split_emotion("[warm] Hello, sir.") == ("Hello, sir.", "warm")


def test_split_no_tag():
    assert tts.split_emotion("Just plain text.") == ("Just plain text.", None)


def test_split_improvised_tag_maps_by_last_word():
    clean, tag = tts.split_emotion("[Mildly excited] here we go")
    assert clean == "here we go"
    assert tag == "excited"


def test_split_unknown_tag_is_stripped_but_unmapped():
    clean, tag = tts.split_emotion("[whatever] text")
    assert clean == "text"
    assert tag is None  # stripped so it's never spoken, but no mood match


def test_protocol_emotion_mapping():
    assert tts.emotion_label("[urgent] Behind you!") == ("Behind you!", "excited")
    assert tts.emotion_label("[sarcastic] sure") == ("sure", "dry")
    assert tts.emotion_label("[serious] listen") == ("listen", "calm")
    assert tts.emotion_label("[neutral] ok") == ("ok", None)
    assert tts.emotion_label("plain") == ("plain", None)


def test_stem_selection():
    assert tts.stem_for("[urgent] now") == "excited"
    assert tts.stem_for("[dry] indeed") == "dry"
    assert tts.stem_for("[warm] hi") == "warm"
    assert tts.stem_for("no tag") is None


def test_protocol_emotion_values_are_in_enum():
    allowed = {"warm", "dry", "excited", "sad", "calm", None}
    for tag in ("calm", "flat", "warm", "happy", "excited", "urgent",
                "alarmed", "sad", "sarcastic", "dry", "serious", "neutral"):
        _clean, emo = tts.emotion_label(f"[{tag}] x")
        assert emo in allowed
