from __future__ import annotations

from dataclasses import dataclass
from enum import Enum

class Outcome(str, Enum):
    NOT_EXECUTED = "not_executed"
    FAILED_NO_EFFECT = "failed_no_effect"
    COMMITTED = "committed"
    UNKNOWN = "unknown"

@dataclass(frozen=True)
class RetryContext:
    outcome: Outcome
    attempts: int
    max_attempts: int
    authorization_valid: bool
    deadline_remaining_ms: int
    idempotency_supported: bool
    is_side_effecting: bool

def retry_decision(ctx: RetryContext) -> str:
    if not ctx.authorization_valid:
        return "stop_authorization"
    if ctx.deadline_remaining_ms <= 0:
        return "stop_deadline"
    if ctx.outcome == Outcome.COMMITTED:
        return "stop_committed"
    if ctx.outcome == Outcome.UNKNOWN:
        return "reconcile_first"
    if ctx.attempts >= ctx.max_attempts:
        return "stop_budget"
    if ctx.is_side_effecting and not ctx.idempotency_supported:
        return "require_effect_verification"
    return "retry_eligible"

assert retry_decision(RetryContext(
    Outcome.UNKNOWN, 1, 3, True, 1000, True, True
)) == "reconcile_first"
assert retry_decision(RetryContext(
    Outcome.COMMITTED, 1, 3, True, 1000, True, True
)) == "stop_committed"
assert retry_decision(RetryContext(
    Outcome.FAILED_NO_EFFECT, 1, 3, True, 1000, True, False
)) == "retry_eligible"
print("local reliability checks passed")
