"""Update admin email from admin@ficher.com to admin@fischer.com"""
import asyncio
import sys
sys.path.insert(0, '/Users/Chiguyong/Code/GEO/backend')

from sqlalchemy import text
from app.database import AsyncSessionLocal

async def main():
    async with AsyncSessionLocal() as session:
        # Check current user
        result = await session.execute(text("SELECT id, email FROM users WHERE email='admin@ficher.com'"))
        row = result.fetchone()
        if row:
            print(f"Found user: id={row[0]}, email={row[1]}")
            await session.execute(text("UPDATE users SET email='admin@fischer.com' WHERE email='admin@ficher.com'"))
            await session.commit()
            print("Email updated to admin@fischer.com")
        else:
            print("No user found with admin@ficher.com")
            result2 = await session.execute(text("SELECT id, email FROM users WHERE email='admin@fischer.com'"))
            row2 = result2.fetchone()
            if row2:
                print(f"Already updated: id={row2[0]}, email={row2[1]}")
            else:
                print("No admin user found at all!")
                all_users = await session.execute(text("SELECT id, email FROM users LIMIT 10"))
                for u in all_users.fetchall():
                    print(f"  User: id={u[0]}, email={u[1]}")

        # Verify
        verify = await session.execute(text("SELECT id, email FROM users WHERE email='admin@fischer.com'"))
        v = verify.fetchone()
        if v:
            print(f"Verified: id={v[0]}, email={v[1]}")
        else:
            print("WARNING: Verification failed - admin@fischer.com not found!")

asyncio.run(main())
