import asyncio
from app.db.session import AsyncSessionLocal
from app.models.identity import User
from app.core.security import create_tokens
from sqlalchemy import select

async def main():
    async with AsyncSessionLocal() as db:
        result = await db.execute(select(User).where(User.id == 29))
        user = result.scalar_one_or_none()
        if not user:
            print("User 29 not found")
            return
            
        print(f"User found: {user.email}, Scope ID: {user.scope_id}")
        
        token_payload = {
            "sub": str(user.id),
            "role": user.role.value if hasattr(user.role, 'value') else user.role,
            "rank": 10,
            "scope_level": user.scope_level.value if hasattr(user.scope_level, 'value') else (user.scope_level or "individual"),
            "scope_id": str(user.scope_id) if user.scope_id else str(user.id)
        }
        access_token, refresh_token = create_tokens(data=token_payload)
        print(f"TOKEN={access_token}")

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