"""
Quick script to update user names without prompts.
Edit the USER_UPDATES dictionary below with your desired names.
"""
from app.core.database import SessionLocal
from app.models.user import User

# Edit these values to match your requirements
USER_UPDATES = {
    'admin': {
        'first_name': 'System',
        'last_name': 'Administrator'
    },
    'superadmin': {
        'first_name': 'Super',
        'last_name': 'Administrator'
    },
    'tanaka': {
        'first_name': 'Tanaka',
        'last_name': 'Muje'
    }
}

def quick_update():
    """Quickly update user names based on USER_UPDATES dictionary."""
    db = SessionLocal()
    try:
        print("=" * 70)
        print("QUICK USER NAME UPDATE")
        print("=" * 70)
        print()

        updated_count = 0
        for username, updates in USER_UPDATES.items():
            user = db.query(User).filter(User.username == username).first()
            if user:
                old_first = user.first_name
                old_last = user.last_name

                user.first_name = updates.get('first_name', user.first_name)
                user.last_name = updates.get('last_name', user.last_name)

                print(f"✓ {username}:")
                print(f"    {old_first} {old_last} → {user.first_name} {user.last_name}")
                updated_count += 1
            else:
                print(f"✗ User '{username}' not found")

        if updated_count > 0:
            db.commit()
            print(f"\n✓ Successfully updated {updated_count} users!")

            # Display all users
            print("\n" + "=" * 70)
            print("ALL USERS:")
            print("=" * 70)
            for user in db.query(User).all():
                print(f"  {user.username:15} | {user.first_name} {user.last_name} ({user.role})")
        else:
            print("\n✗ No users were updated.")

    except Exception as e:
        print(f"\n❌ Error: {e}")
        db.rollback()
    finally:
        db.close()

if __name__ == "__main__":
    quick_update()
