from services.rpg_plot import (
    choices_from_beat,
    choices_from_narrator,
    normalize_choice,
    format_beat_injection_for_character,
)


def test_choices_from_beat_tags_source():
    beat = {
        "id": "b_new_1",
        "title": "Rest Stop Confession",
        "injection": "GPS alerts you to a rest stop.",
        "choices": [
            {"id": "a", "label": "Tease her about snores"},
            {"id": "b", "label": "Ask about snacks"},
        ],
    }
    out = choices_from_beat(beat)
    assert len(out) == 2
    assert out[0]["source"] == "plot_step"
    assert out[0]["beat_title"] == "Rest Stop Confession"
    assert out[0]["beat_id"] == "b_new_1"
    assert "beat_injection" in out[0]


def test_choices_from_narrator_tags_source():
    out = choices_from_narrator([{"id": "a", "label": "Look around"}])
    assert out[0]["source"] == "narrator"
    assert "beat_title" not in out[0]


def test_beat_injection_block_for_character_prompt():
    block = format_beat_injection_for_character(
        "Over pancakes, Luna steals glances at you.",
        lang="en",
    )
    assert "Plot hint" in block
    assert "Over pancakes" in block
    assert format_beat_injection_for_character("") == ""


def test_beat_injection_block_ru():
    block = format_beat_injection_for_character(
        "Луна крадёт взгляды через блины.",
        lang="ru",
    )
    assert "Сюжетная подсказка" in block
    assert "по-русски" in block


def test_normalize_choice_skips_empty_label():
    assert normalize_choice({"id": "a", "label": "  "}, source="narrator") is None
