#!/usr/bin/env python3
"""
Migration script to add PvP statistics columns
"""
import asyncio
import sys
import os

# Add parent directory to path
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))

from api.database import engine

async def migrate():
    """Add PvP statistics columns to player_statistics table"""
    async with engine.begin() as conn:
        print("Adding PvP statistics columns...")
        
        # Add PvP columns
        await conn.execute(text("""
            ALTER TABLE player_statistics 
            ADD COLUMN IF NOT EXISTS pvp_combats_initiated INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS pvp_combats_won INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS pvp_combats_lost INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS pvp_damage_dealt INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS pvp_damage_taken INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS players_killed INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS pvp_deaths INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS pvp_successful_flees INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS pvp_failed_flees INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS pvp_attacks_landed INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS pvp_attacks_received INTEGER DEFAULT 0
        """))
        
        print("✅ PvP statistics columns added successfully!")

if __name__ == "__main__":
    from sqlalchemy import text
    print("=== PvP Statistics Migration ===")
    asyncio.run(migrate())
    print("Migration complete!")
