#!/usr/bin/env python3
"""
Debug script to test input extraction
"""

import requests
import json

def test_input_extraction():
    """Test how the webhook processes different input formats"""
    
    url = "http://localhost:5678/webhook/agent-task"
    
    # Test different input formats
    test_cases = [
        {
            "name": "Message only",
            "payload": {"message": "Help me build a mobile app"}
        },
        {
            "name": "Task only", 
            "payload": {"task": "Help me build a mobile app"}
        },
        {
            "name": "Both message and task",
            "payload": {"message": "Help me build a mobile app", "task": "Create a mobile app"}
        },
        {
            "name": "Empty message",
            "payload": {"message": ""}
        },
        {
            "name": "No input fields",
            "payload": {}
        }
    ]
    
    for test_case in test_cases:
        print(f"\n=== {test_case['name']} ===")
        print(f"Payload: {json.dumps(test_case['payload'], indent=2)}")
        
        try:
            response = requests.post(url, json=test_case['payload'], timeout=10)
            print(f"Status: {response.status_code}")
            
            if response.status_code == 200:
                data = response.json()
                print(f"Success: {data.get('success', False)}")
                print(f"Error: {data.get('error', 'None')}")
                if 'received_data' in data:
                    print(f"Received data: {data['received_data']}")
            else:
                print(f"Response: {response.text}")
                
        except Exception as e:
            print(f"Error: {e}")

if __name__ == "__main__":
    test_input_extraction()
