"""تصحيح last_triggered في قواعد التنبيهات"""
import asyncio
from datetime import timedelta
from app.database import AsyncSessionLocal
from app.models.alert import AlertRule
from sqlalchemy import select

async def fix():
    async with AsyncSessionLocal() as session:
        result = await session.execute(select(AlertRule))
        rules = result.scalars().all()
        
        for rule in rules:
            if rule.last_triggered:
                # إرجاع 3 ساعات
                rule.last_triggered = rule.last_triggered - timedelta(hours=3)
                print(f"Fixed {rule.name}: {rule.last_triggered}")
        
        await session.commit()

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