"""Area #2 W8c — state and gaze e2e (producer → router → state-variant generation).

producer shot_staging v13 (3 field: gaze_direction_kind / gaze_target_id /
subject_state) emit → router build_semantic_contract Rule 1 read (subject_state
SOT) → state-variant generation 의 get_visual_descriptor helper read 한 path
verify. W1-W7 atomic wave 의 종합 e2e closure.
"""
from __future__ import annotations


def test_e2e_router_immobilized_via_subject_state():
    """semantic_contract_router Rule 1 subject_state read 정합.

    v13 shape (3 field) staging → build_semantic_contract → primary_mode ==
    "immobilized". 본 path 가 Patch B-min wiring 의 SOT (이전 IMMOBILIZED_GAZE
    frozenset 분기, W3 폐기) 를 대체.
    """
    from app.modules.semantic_contract_router import build_semantic_contract

    contract = build_semantic_contract(
        shot_staging={
            "character_angles": [
                {
                    "character": "Alpha",
                    "angle": "back_to_camera",
                    "body_pose": "lying motionless",
                    "gaze_direction_kind": "closed_eyes",
                    "subject_state": "dead",
                },
            ],
        },
        render_prompt_card=None,
        visible_entities=[
            {"name": "Alpha", "short_id": "C01", "entity_type": "character"}
        ],
    )

    assert contract.primary_mode == "immobilized"
    assert contract.immobilized_entity_ids == ("C01",)
    # evidence source 가 신 SOT key 정합 — W3 commit 후 변경
    assert any(
        ev["source"] == "shot_staging.character_angles.subject_state"
        for ev in contract.evidence
    ), f"evidence source 오인식: {contract.evidence}"


def test_get_visual_descriptor_dead_returns_motionless_prose():
    """helper `get_visual_descriptor("dead")` unit verify — W4 closure 의 SOT
    (STATE_DESCRIPTIONS dict, 폐기) 대체 helper. CharacterStateVariantStep
    full e2e integration 은 W4 source-grep test (test_character_state_variant_step)
    가 cover — 본 test 는 helper output unit verify only.
    """
    from app.core.subject_state import get_visual_descriptor

    desc = get_visual_descriptor("dead")

    assert "motionless" in desc or "lifeless" in desc, (
        f"get_visual_descriptor('dead') = {desc!r} — expected descriptor with "
        f"motionless or lifeless prose"
    )
