from __future__ import annotations

from app.services.session_context import extract_protocol


def test_extract_protocol_prefers_start_payload_data() -> None:
    protocol = extract_protocol(
        {
            "data": {
                "protocolo": "PRT-123",
            }
        },
        {"protocolo": "PRT-999"},
    )

    assert protocol == "PRT-123"


def test_extract_protocol_falls_back_to_session_data() -> None:
    protocol = extract_protocol(
        {"data": {}},
        {"protocolo": "PRT-999"},
    )

    assert protocol == "PRT-999"


def test_extract_protocol_falls_back_to_router_call_key_when_protocol_is_missing() -> None:
    protocol = extract_protocol(
        {
            "data": {
                "routerCallKey": "RCK-123",
            }
        },
        {},
    )

    assert protocol == "RCK-123"


def test_extract_protocol_accepts_protocol_id() -> None:
    protocol = extract_protocol(
        {
            "data": {
                "protocol_id": "PRT-777",
                "routerCallKey": "RCK-123",
            }
        },
        {},
    )

    assert protocol == "PRT-777"
