#!/usr/bin/env python3
"""
Direct test of the projects endpoint to catch detailed errors.
"""

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from database import get_db
from routers.projects import list_projects
from utils.auth import _get_user_from_db
from models.user import User

def test_projects_direct():
    """Test projects endpoint directly."""
    
    print("Testing Projects Endpoint Directly")
    print("=" * 40)
    
    try:
        # Get database session
        db = next(get_db())
        
        # Get admin user
        admin_user = db.query(User).filter(User.email == "admin@vfx.com").first()
        if not admin_user:
            print("❌ Admin user not found")
            return
        
        print(f"✅ Found admin user: {admin_user.email} (Role: {admin_user.role})")
        
        # Call the projects endpoint directly
        print("\nCalling list_projects endpoint...")
        import asyncio
        result = asyncio.run(list_projects(skip=0, limit=100, db=db, current_user=admin_user))
        
        print(f"✅ Success! Found {len(result)} projects:")
        for project in result:
            print(f"   - {project.name} ({project.code_name})")
        
    except Exception as e:
        print(f"❌ Error: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    test_projects_direct()