"""
Simple script to test the API endpoints
Run this after starting the server to verify everything works
"""

import requests
import json

BASE_URL = "http://localhost:8000"

def test_health():
    """Test health endpoint"""
    print("\n" + "="*60)
    print("Testing /health endpoint...")
    print("="*60)
    
    try:
        response = requests.get(f"{BASE_URL}/health")
        print(f"Status Code: {response.status_code}")
        print(f"Response: {json.dumps(response.json(), indent=2)}")
        return response.status_code == 200
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

def test_root():
    """Test root endpoint"""
    print("\n" + "="*60)
    print("Testing / endpoint...")
    print("="*60)
    
    try:
        response = requests.get(f"{BASE_URL}/")
        print(f"Status Code: {response.status_code}")
        print(f"Response: {json.dumps(response.json(), indent=2)}")
        return response.status_code == 200
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

def test_stats():
    """Test stats endpoint"""
    print("\n" + "="*60)
    print("Testing /stats endpoint...")
    print("="*60)
    
    try:
        response = requests.get(f"{BASE_URL}/stats")
        print(f"Status Code: {response.status_code}")
        print(f"Response: {json.dumps(response.json(), indent=2)}")
        return response.status_code == 200
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

def main():
    print("\n" + "🧪 API Testing Script")
    print("Make sure the backend server is running on http://localhost:8000\n")
    
    results = {
        "Root Endpoint": test_root(),
        "Health Check": test_health(),
        "Stats Endpoint": test_stats()
    }
    
    print("\n" + "="*60)
    print("📊 Test Results Summary")
    print("="*60)
    
    for test_name, passed in results.items():
        status = "✅ PASSED" if passed else "❌ FAILED"
        print(f"{test_name}: {status}")
    
    all_passed = all(results.values())
    
    print("\n" + "="*60)
    if all_passed:
        print("🎉 All tests passed! Your API is working correctly.")
        print("\nYou can now:")
        print("1. Open http://localhost:8000/docs for interactive API documentation")
        print("2. Start the frontend with 'npm run dev' in the frontend folder")
        print("3. Upload images to test the verification system")
    else:
        print("⚠️  Some tests failed. Please check:")
        print("1. Is the backend server running?")
        print("2. Are the models loaded correctly?")
        print("3. Check the server logs for errors")
    print("="*60 + "\n")

if __name__ == "__main__":
    main()
