from GramAddict.core.perception.intent_resolver import IntentResolver
from GramAddict.core.perception.spatial_parser import SpatialNode


def test_semantic_guard_allows_multilingual_follow_button():
    """
    RED: The IntentResolver's Semantic Guard used to hard-filter for EXACT quotes.
    If the plugin requested "tap 'Follow' button", but the UI was in German ("Abonnieren"),
    the Semantic Guard would block it, causing the bot to never follow anyone.
    GREEN: We added multilingual equivalents to the Semantic Guard logic.
    """
    resolver = IntentResolver()

    intent = "tap 'Follow' button"

    # Create a node that represents a German follow button
    german_node = SpatialNode(
        resource_id="com.instagram.android:id/profile_header_follow_button",
        content_desc="Abonnieren",
        text="Abonnieren",
        bounds=(0, 0, 100, 100),
    )

    # Run the resolver without a device (forces semantic/structural resolution, bypasses VLM)
    result = resolver.resolve(intent, candidates=[german_node], device=None, screen_height=2000)

    assert result is not None
    assert result.text == "Abonnieren"


def test_semantic_guard_allows_multilingual_following_button():
    """
    Ensures that "tap 'Following' button" resolves correctly for German UIs
    ("Abonniert", "Gefolgt", "Angefragt").
    """
    resolver = IntentResolver()

    intent = "tap 'Following' button"

    # Create a node that represents a German "Following" button
    german_node = SpatialNode(
        resource_id="com.instagram.android:id/profile_header_follow_button",
        content_desc="Abonniert",
        text="Abonniert",
        bounds=(0, 0, 100, 100),
    )

    result = resolver.resolve(intent, candidates=[german_node], device=None, screen_height=2000)

    assert result is not None
    assert result.text == "Abonniert"
