"""تصحيح وقت التنبيه الأخير"""
import asyncio
from datetime import timedelta
from app.database import AsyncSessionLocal
from app.models.alert import AlertLog
from sqlalchemy import select

async def fix_time():
    async with AsyncSessionLocal() as session:
        result = await session.execute(select(AlertLog).where(AlertLog.id == 3))
        log = result.scalar_one_or_none()
        
        if log:
            # إرجاع 3 ساعات (لأنه تم إضافتها مرتين)
            log.triggered_at = log.triggered_at - timedelta(hours=3)
            await session.commit()
            print(f"✓ Fixed alert ID 3: {log.triggered_at}")

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