#!/usr/bin/env python3
"""
Verify User Data
This script verifies what data is available for a specific user.
"""

import os
from pymongo import MongoClient

def verify_user_data():
    """Verify data for the main user"""
    print("🔍 Verifying User Data")
    print("=" * 50)
    
    try:
        mongo_uri = os.getenv('MONGODB_URI')
        mongo_db = os.getenv('MONGODB_DB')
        
        if not mongo_uri or not mongo_db:
            print("❌ MongoDB configuration not found")
            return
            
        client = MongoClient(mongo_uri)
        db = client[mongo_db]
        
        # Check the correct user ID that the user is logged in as
        user_id = '3468924c-fa4f-4d21-90b5-09f1602c57f0'
        
        print(f"👤 Checking data for user: {user_id}")
        
        # Get recent recordings
        recordings = list(db.codegen_recordings.find({'userId': user_id}).sort('date', -1).limit(10))
        print(f"\n📊 Recent Recordings ({len(recordings)} shown):")
        for i, rec in enumerate(recordings, 1):
            name = rec.get('name', 'Unknown')
            date = rec.get('date', 'Unknown')
            print(f"  {i}. {name} - {date}")
        
        total_recordings = db.codegen_recordings.count_documents({'userId': user_id})
        print(f"\n📈 Total recordings for this user: {total_recordings}")
        
        # Check test cases
        test_cases = list(db.test_cases.find({'user_id': user_id}).sort('created_at', -1).limit(5))
        print(f"\n📋 Recent Test Cases ({len(test_cases)} shown):")
        for i, tc in enumerate(test_cases, 1):
            tc_id = tc.get('_id', 'Unknown')
            source_type = tc.get('source_type', 'Unknown')
            created = tc.get('created_at', 'Unknown')
            print(f"  {i}. {tc_id} - {source_type} - {created}")
        
        total_test_cases = db.test_cases.count_documents({'user_id': user_id})
        print(f"\n📈 Total test cases for this user: {total_test_cases}")
        
        # Check generated scripts
        scripts = list(db.generated_scripts.find({'user_id': user_id}).sort('created_at', -1).limit(5))
        print(f"\n🔧 Recent Generated Scripts ({len(scripts)} shown):")
        for i, script in enumerate(scripts, 1):
            script_id = script.get('_id', 'Unknown')
            source_type = script.get('source_type', 'Unknown')
            created = script.get('created_at', 'Unknown')
            print(f"  {i}. {script_id} - {source_type} - {created}")
        
        total_scripts = db.generated_scripts.count_documents({'user_id': user_id})
        print(f"\n📈 Total generated scripts for this user: {total_scripts}")
        
        print(f"\n✅ Data Summary:")
        print(f"   - Recordings: {total_recordings}")
        print(f"   - Test Cases: {total_test_cases}")
        print(f"   - Scripts: {total_scripts}")
        
        client.close()
        
    except Exception as e:
        print(f"❌ Error: {e}")

if __name__ == "__main__":
    verify_user_data()


