#!/usr/bin/env python3

import json
import requests
import time

# Test login endpoint with detailed logging
def test_login():
    """Test login with various scenarios"""
    base_url = "http://localhost:8000"
    
    # Test cases
    test_cases = [
        {
            "name": "Empty request",
            "data": {}
        },
        {
            "name": "Only password",
            "data": {"password": "testpass123"}
        },
        {
            "name": "Only email", 
            "data": {"email": "test@example.com"}
        },
        {
            "name": "Valid email and password",
            "data": {
                "email": "test@example.com",
                "password": "testpass123"
            }
        },
        {
            "name": "Valid username and password",
            "data": {
                "username": "testuser",
                "password": "testpass123"
            }
        },
        {
            "name": "Invalid JSON format",
            "data": "invalid json",
            "content_type": "text/plain"
        }
    ]
    
    for test_case in test_cases:
        print(f"\n🧪 Testing: {test_case['name']}")
        print("=" * 50)
        
        try:
            headers = {
                "Content-Type": test_case.get("content_type", "application/json"),
                "Accept": "application/json"
            }
            
            if isinstance(test_case["data"], dict):
                data = json.dumps(test_case["data"])
                print(f"Request data: {data}")
            else:
                data = test_case["data"]
                print(f"Request data (raw): {data}")
            
            response = requests.post(
                f"{base_url}/api/v1/auth/login",
                data=data,
                headers=headers,
                timeout=10
            )
            
            print(f"Status Code: {response.status_code}")
            print(f"Headers: {dict(response.headers)}")
            print(f"Response: {response.text}")
            
        except Exception as e:
            print(f"Error: {str(e)}")
        
        time.sleep(1)  # Wait between requests

if __name__ == "__main__":
    print("🔍 Testing login endpoint with detailed logging")
    print("Make sure to check the server logs for debugging info")
    test_login()