"""اختبار أول تنبيه بعد dashboard_refresh_interval"""
import asyncio
import time
from app.database import AsyncSessionLocal
from app.models.alert import AlertRule, AlertLog
from sqlalchemy import select, update

async def reset_alerts():
    async with AsyncSessionLocal() as session:
        # حل جميع التنبيهات
        await session.execute(
            update(AlertLog).values(is_resolved=True)
        )
        # إعادة ضبط condition_first_detected
        await session.execute(
            update(AlertRule).values(condition_first_detected=None)
        )
        await session.commit()
        print("✓ Reset all alerts and condition_first_detected")

if __name__ == "__main__":
    asyncio.run(reset_alerts())
    
    print("\n=== Test 1: First detection (should wait) ===")
    from app.tasks.alert_tasks import check_device_alerts
    result1 = check_device_alerts()
    print(f"Result: {result1}")
    
    print("\n=== Waiting 35 seconds... ===")
    time.sleep(35)
    
    print("\n=== Test 2: After waiting (should send alert) ===")
    result2 = check_device_alerts()
    print(f"Result: {result2}")
