import datetime as dt

from flashops_control.config import TimingPolicy
from flashops_control.enums import HostStatus
from flashops_control.services.agent_status import projected_agent_status


NOW = dt.datetime(2026, 7, 27, 12, 0, 0)
TIMING = TimingPolicy(
    heartbeat_interval_s=5,
    heartbeat_degraded_after_s=15,
    heartbeat_lost_after_s=30,
)


def test_fresh_agent_heartbeat_is_online():
    status = projected_agent_status(
        NOW - dt.timedelta(seconds=14),
        HostStatus.ONLINE.value,
        now=NOW,
        timing=TIMING,
    )
    assert status == HostStatus.ONLINE.value


def test_late_agent_heartbeat_is_degraded():
    status = projected_agent_status(
        NOW - dt.timedelta(seconds=15),
        HostStatus.ONLINE.value,
        now=NOW,
        timing=TIMING,
    )
    assert status == HostStatus.DEGRADED.value


def test_lost_agent_heartbeat_is_offline():
    status = projected_agent_status(
        NOW - dt.timedelta(seconds=30),
        HostStatus.DEGRADED.value,
        now=NOW,
        timing=TIMING,
    )
    assert status == HostStatus.OFFLINE.value


def test_fresh_unhealthy_agent_stays_degraded_until_healthy_report():
    status = projected_agent_status(
        NOW,
        HostStatus.DEGRADED.value,
        now=NOW,
        timing=TIMING,
    )
    assert status == HostStatus.DEGRADED.value
