"""
Migration: Add unique item properties to dropped_items table

This migration adds durability, max_durability, tier, and unique_stats columns
to the dropped_items table so that dropped equipment items preserve their state.
"""

import asyncio
from api.database import DatabaseSession, engine, metadata
from sqlalchemy import text

async def migrate():
    """Add unique item columns to dropped_items"""
    
    async with DatabaseSession() as session:
        print("Starting migration: Add unique item properties to dropped_items...")
        
        # Add durability column
        try:
            await session.execute(text(
                "ALTER TABLE dropped_items ADD COLUMN durability INTEGER"
            ))
            print("✓ Added durability column")
        except Exception as e:
            print(f"✗ durability column may already exist: {e}")
        
        # Add max_durability column
        try:
            await session.execute(text(
                "ALTER TABLE dropped_items ADD COLUMN max_durability INTEGER"
            ))
            print("✓ Added max_durability column")
        except Exception as e:
            print(f"✗ max_durability column may already exist: {e}")
        
        # Add tier column
        try:
            await session.execute(text(
                "ALTER TABLE dropped_items ADD COLUMN tier INTEGER DEFAULT 1"
            ))
            print("✓ Added tier column")
        except Exception as e:
            print(f"✗ tier column may already exist: {e}")
        
        # Add unique_stats JSONB column
        try:
            await session.execute(text(
                "ALTER TABLE dropped_items ADD COLUMN unique_stats JSONB"
            ))
            print("✓ Added unique_stats column")
        except Exception as e:
            print(f"✗ unique_stats column may already exist: {e}")
        
        await session.commit()
        print("\n✓ Migration completed successfully!")

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