"""五级恢复阶梯的纯函数决策。"""
from __future__ import annotations

from dataclasses import dataclass

from ..enums import RecoveryLevel, RecoveryTrigger


@dataclass(frozen=True)
class RecoveryContext:
    trigger: RecoveryTrigger
    attempt: int
    agent_online: bool
    host_network_online: bool
    oob_online: bool


def next_recovery_level(context: RecoveryContext) -> RecoveryLevel:
    if context.trigger == RecoveryTrigger.DATA_INTEGRITY:
        return RecoveryLevel.FREEZE

    ladder = []
    if context.agent_online:
        ladder.append(RecoveryLevel.AGENT_SOFT)
    if context.host_network_online:
        ladder.append(RecoveryLevel.OS_REBOOT)
    if context.oob_online:
        ladder.extend(
            [
                RecoveryLevel.OOB_RESET,
                RecoveryLevel.OOB_ATX_POWER,
                RecoveryLevel.OOB_AC_CYCLE,
            ]
        )
    if context.attempt >= len(ladder):
        return RecoveryLevel.FREEZE
    return ladder[context.attempt]
