from celery import shared_task

from .services import cleanup_monitor_history, run_due_monitors, run_monitor_check


@shared_task(name="monitoring.run_monitor")
def run_monitor_task(monitor_id):
    check = run_monitor_check(monitor_id)
    return {
        "monitor_id": monitor_id,
        "check_id": check.pk,
        "result": check.result,
        "http_status": check.http_status,
        "response_time_ms": check.response_time_ms,
    }


@shared_task(name="monitoring.run_due_monitors")
def run_due_monitors_task():
    return run_due_monitors()


@shared_task(name="monitoring.cleanup_history")
def cleanup_monitor_history_task():
    return cleanup_monitor_history()
