"""إصلاح شرط قاعدة التنبيه"""
import asyncio
from app.database import AsyncSessionLocal
from app.models.alert import AlertRule, AlertLog
from sqlalchemy import select, update

async def fix():
    async with AsyncSessionLocal() as session:
        # إصلاح الشرط
        await session.execute(
            update(AlertRule).where(AlertRule.name == "Room 3>10").values(
                condition_type="greater_than",
                threshold_value=10.0
            )
        )
        
        # إعادة التنبيهات إلى غير محلولة
        await session.execute(
            update(AlertLog).values(is_resolved=False, resolved_at=None)
        )
        
        await session.commit()
        print("✓ Fixed rule condition to greater_than 10")
        print("✓ Reset alerts to unresolved")

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