#!/usr/bin/env python3
"""
Script to set high stamina for load test users
Run this inside the container after creating test users
"""
import asyncio
import sys
import os

# Add parent directory to path
sys.path.insert(0, '/app')

from api import database as db

async def set_test_user_stamina(stamina: int = 100000):
    """Set high stamina for all loadtest users"""
    async with db.DatabaseSession() as session:
        from sqlalchemy import select, update
        
        # Get all loadtest users
        stmt = select(db.players).where(db.players.c.username.like('loadtest_user_%'))
        result = await session.execute(stmt)
        users = result.all()
        
        print(f"Found {len(users)} loadtest users")
        
        if not users:
            print("No loadtest users found!")
            return
        
        # Update stamina for all test users
        stmt = update(db.players).where(
            db.players.c.username.like('loadtest_user_%')
        ).values(stamina=stamina, max_stamina=stamina)
        
        await session.execute(stmt)
        await session.commit()
        
        print(f"Updated stamina to {stamina} for all loadtest users")

if __name__ == "__main__":
    stamina_value = int(sys.argv[1]) if len(sys.argv) > 1 else 100000
    asyncio.run(set_test_user_stamina(stamina_value))
