#!/usr/bin/env python3
"""Test router imports and FastAPI app creation."""
import sys
import traceback

def test_router_imports():
    """Test that all routers can be imported."""
    print("Testing router imports...")
    try:
        from app.routers import *
        print("✅ All routers imported successfully")
        return True
    except Exception as e:
        print(f"❌ Router import error: {e}")
        traceback.print_exc()
        return False

def test_fastapi_app():
    """Test that FastAPI app can be created."""
    print("\nTesting FastAPI app creation...")
    try:
        from app.main import app
        print("✅ FastAPI app created successfully")
        print(f"   App title: {app.title}")
        print(f"   App version: {app.version}")
        return True
    except Exception as e:
        print(f"❌ FastAPI app creation error: {e}")
        traceback.print_exc()
        return False

def test_schema_imports():
    """Test that schemas are properly imported."""
    print("\nTesting schema imports...")
    try:
        from app.schemas import (
            MessageResponse, CountResponse,
            CardCollectionCreate, CardCollectionResponse,
            WishlistCreate, WishlistResponse,
        )
        print("✅ Schema imports successful")
        return True
    except Exception as e:
        print(f"❌ Schema import error: {e}")
        traceback.print_exc()
        return False

if __name__ == "__main__":
    print("=" * 60)
    print("Phase 4: Router Layer Testing")
    print("=" * 60)
    
    results = []
    results.append(("Router Imports", test_router_imports()))
    results.append(("FastAPI App", test_fastapi_app()))
    results.append(("Schema Imports", test_schema_imports()))
    
    print("\n" + "=" * 60)
    print("Test Results Summary")
    print("=" * 60)
    for test_name, passed in results:
        status = "✅ PASS" if passed else "❌ FAIL"
        print(f"{test_name:20} {status}")
    
    all_passed = all(result[1] for result in results)
    print("\n" + ("=" * 60))
    if all_passed:
        print("✅ ALL TESTS PASSED")
        sys.exit(0)
    else:
        print("❌ SOME TESTS FAILED")
        sys.exit(1)
