from __future__ import annotations

from src.tools import telegram_alert_smoke


def test_run_alert_smoke_can_filter_to_critical_only(monkeypatch):
    monkeypatch.setattr(
        telegram_alert_smoke.TelegramAlertConfig,
        "from_env",
        classmethod(lambda cls: telegram_alert_smoke.TelegramAlertConfig(enabled=True, bot_token="x", chat_id="1", thread_id=2)),
    )

    payload = telegram_alert_smoke.run_alert_smoke(dry_run=True, only=("critical_reconcile",))

    assert payload["status"] == "ok"
    assert [item["name"] for item in payload["alerts"]] == ["critical_reconcile"]
    assert payload["alerts"][0]["sent"] is False
    assert payload["alerts"][0]["reason"] == "dry_run"


def test_run_alert_smoke_reports_no_matching_alerts(monkeypatch):
    monkeypatch.setattr(
        telegram_alert_smoke.TelegramAlertConfig,
        "from_env",
        classmethod(lambda cls: telegram_alert_smoke.TelegramAlertConfig(enabled=True, bot_token="x", chat_id="1", thread_id=2)),
    )

    payload = telegram_alert_smoke.run_alert_smoke(dry_run=True, only=("missing",))

    assert payload["status"] == "skipped"
    assert payload["reason"] == "no_matching_alerts"
    assert payload["alerts"] == []
