"""Tests for intelligent routing logic.

Generated by GRIMLOCK MCP Factory
"""

import pytest
from videogen_mcp.router import detect_service, validate_service_hint


class TestDetectService:
    """Test cases for detect_service function."""

    def test_heygen_keyword_speak(self):
        """Prompt with 'speak' should route to HeyGen."""
        assert detect_service("Create a video where someone speaks about AI") == "heygen"

    def test_heygen_keyword_present(self):
        """Prompt with 'present' should route to HeyGen."""
        assert detect_service("I need a presenter to present our product") == "heygen"

    def test_heygen_keyword_tutorial(self):
        """Prompt with 'tutorial' should route to HeyGen."""
        assert detect_service("Make a tutorial explaining how to use the app") == "heygen"

    def test_heygen_keyword_avatar(self):
        """Prompt with 'avatar' should route to HeyGen."""
        assert detect_service("Use an avatar to introduce our company") == "heygen"

    def test_heygen_keyword_narrator(self):
        """Prompt with 'narrator' should route to HeyGen."""
        assert detect_service("I need a narrator to narrate the story") == "heygen"

    def test_heygen_keyword_walkthrough(self):
        """Prompt with 'walk through' should route to HeyGen."""
        assert detect_service("Create a video that walks through the features") == "heygen"

    def test_heygen_keyword_talking_head(self):
        """Prompt with 'talking head' should route to HeyGen."""
        assert detect_service("A talking head video for YouTube") == "heygen"

    def test_heygen_with_quoted_speech(self):
        """Prompt with quoted speech should route to HeyGen."""
        assert detect_service('Have someone say: "Welcome to our company!"') == "heygen"

    def test_veo_keyword_cinematic(self):
        """Prompt with 'cinematic' should route to Veo."""
        assert detect_service("Create a cinematic opening shot of the city") == "veo"

    def test_veo_keyword_broll(self):
        """Prompt with 'b-roll' should route to Veo."""
        assert detect_service("Generate b-roll footage of nature") == "veo"

    def test_veo_keyword_animation(self):
        """Prompt with 'animation' should route to Veo."""
        assert detect_service("Create an abstract animation with particles") == "veo"

    def test_veo_keyword_aerial(self):
        """Prompt with 'aerial' should route to Veo."""
        assert detect_service("Aerial drone shot over mountains") == "veo"

    def test_veo_keyword_timelapse(self):
        """Prompt with 'timelapse' should route to Veo."""
        assert detect_service("Generate a timelapse of the sunset") == "veo"

    def test_veo_keyword_slow_motion(self):
        """Prompt with 'slow motion' should route to Veo."""
        assert detect_service("Slow motion shot of water droplets") == "veo"

    def test_veo_keyword_dolly(self):
        """Prompt with 'dolly' should route to Veo."""
        assert detect_service("A slow dolly shot through the forest") == "veo"

    def test_veo_keyword_establishing_shot(self):
        """Prompt with 'establishing shot' should route to Veo."""
        assert detect_service("Create an establishing shot of the building") == "veo"

    def test_veo_keyword_nature(self):
        """Prompt about nature should route to Veo."""
        assert detect_service("Beautiful ocean waves at sunset") == "veo"

    def test_veo_keyword_abstract(self):
        """Prompt with 'abstract' should route to Veo."""
        assert detect_service("Abstract colorful patterns flowing") == "veo"

    def test_ambiguous_defaults_to_veo(self):
        """Ambiguous prompts should default to Veo."""
        assert detect_service("Create a video about technology") == "veo"

    def test_empty_prompt_defaults_to_veo(self):
        """Empty prompt should default to Veo."""
        assert detect_service("") == "veo"

    def test_mixed_keywords_heygen_wins(self):
        """When HeyGen keywords are stronger, should route to HeyGen."""
        # Has 'cinematic' (Veo) but 'presenter speaking' (HeyGen x2)
        assert detect_service("Cinematic video with a presenter speaking about tech") == "heygen"

    def test_mixed_keywords_veo_wins(self):
        """When Veo keywords are stronger, should route to Veo."""
        # Has 'tutorial' (HeyGen) but multiple Veo keywords
        assert detect_service("Cinematic aerial drone footage for a visual tutorial") == "veo"

    def test_person_speaking_pattern(self):
        """Pattern 'person speaking' should route to HeyGen."""
        assert detect_service("A woman speaking about climate change") == "heygen"

    def test_camera_movement_pattern(self):
        """Pattern 'camera movement' should boost Veo."""
        assert detect_service("Smooth camera movement through the space") == "veo"

    def test_script_keyword(self):
        """Prompt mentioning 'script' should route to HeyGen."""
        assert detect_service("Read this script to the camera") == "heygen"


class TestValidateServiceHint:
    """Test cases for validate_service_hint function."""

    def test_heygen_lowercase(self):
        """'heygen' should be valid."""
        assert validate_service_hint("heygen") == "heygen"

    def test_heygen_uppercase(self):
        """'HEYGEN' should normalize to 'heygen'."""
        assert validate_service_hint("HEYGEN") == "heygen"

    def test_heygen_mixed_case(self):
        """'HeyGen' should normalize to 'heygen'."""
        assert validate_service_hint("HeyGen") == "heygen"

    def test_heygen_with_space(self):
        """'hey gen' should normalize to 'heygen'."""
        assert validate_service_hint("hey gen") == "heygen"

    def test_heygen_with_hyphen(self):
        """'hey-gen' should normalize to 'heygen'."""
        assert validate_service_hint("hey-gen") == "heygen"

    def test_veo_lowercase(self):
        """'veo' should be valid."""
        assert validate_service_hint("veo") == "veo"

    def test_veo_uppercase(self):
        """'VEO' should normalize to 'veo'."""
        assert validate_service_hint("VEO") == "veo"

    def test_google_veo(self):
        """'google veo' should normalize to 'veo'."""
        assert validate_service_hint("google veo") == "veo"

    def test_gemini(self):
        """'gemini' should normalize to 'veo'."""
        assert validate_service_hint("gemini") == "veo"

    def test_none_input(self):
        """None input should return None."""
        assert validate_service_hint(None) is None

    def test_invalid_service(self):
        """Invalid service should return None."""
        assert validate_service_hint("youtube") is None

    def test_whitespace(self):
        """Whitespace should be trimmed."""
        assert validate_service_hint("  heygen  ") == "heygen"
