#!/usr/bin/env python3
"""Update admin email from techzone to prompttech"""

import asyncio
import sys
from sqlalchemy import select, update
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker

sys.path.append('/media/pts/Website/PromptTech_Solution_Site/backend')
from models import User, UserRole
from database import DATABASE_URL

async def update_admin_email():
    engine = create_async_engine(DATABASE_URL, echo=False)
    async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
    
    async with async_session() as session:
        # Find admin user with old email
        result = await session.execute(
            select(User).where(User.email == "admin@techzone.com")
        )
        admin = result.scalar_one_or_none()
        
        if admin:
            print(f"✓ Found admin user: {admin.email}")
            admin.email = "admin@prompttech.com"
            await session.commit()
            print(f"✓ Updated admin email to: admin@prompttech.com")
            print(f"\nNew credentials:")
            print(f"  Email: admin@prompttech.com")
            print(f"  Password: admin123")
        else:
            print("✗ Admin user with email admin@techzone.com not found")
            # Show all users
            result = await session.execute(select(User))
            users = result.scalars().all()
            print(f"\nFound {len(users)} users:")
            for user in users:
                print(f"  - {user.email} ({user.role.value})")

if __name__ == "__main__":
    asyncio.run(update_admin_email())
