from fastapi import APIRouter
import database as db
import simulator
from logger import get_logger
logger = get_logger(__name__)

router = APIRouter(prefix="/simulator", tags=["simulator"])

@router.get("/status")
def get_status():
    conn = db.connect_to_db()
    try:
        stats = db.get_simulator_stats(conn)
        return {
            **stats,
            "next_alarm_cleanup_at": simulator.next_alarm_cleanup_at,
            "next_incident_cleanup_at": simulator.next_incident_cleanup_at,
        }
    except Exception as e:
        logger.error(f"Ticket simulator /api/v1/status error: {e}", exc_info=True)
        return {}
    finally:
        conn.close()
