# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-scope-cure-periods-to-observable-remediation-time.md
# Remnant Warrant:    https://corpusfetch.com/c/how-must-an-instance-scope-cure-periods-to-observable-remediation-time.warrant.json
# Markdown SHA-256:   35027ee5ecf5ecffeb88683a1d4de9580ec8e98451f9293ba72df55bd62aea44
# Code AST SHA-256:   1b270d76479b9f1ae57478aec57df748d20440a67aba4fdbb2c92fe11fdf0ee9
# Verified Classes:   CureWindowTrapError, CureWindowGate
# Defensive Guards:   2 fail-closed invariants (zero external deps)

from dataclasses import dataclass


class CureWindowTrapError(RuntimeError):
    """Raised when a cure period cannot contain remediation and verification time."""


@dataclass(frozen=True)
class CureWindowGate:
    cure_window_days: int
    remediation_p99_days: int
    verification_latency_days: int
    defect_class_measured: bool = True

    def verify(self) -> bool:
        if not self.defect_class_measured:
            raise CureWindowTrapError(
                "no remediation p99 for this defect class: cure window feasibility unknown"
            )
        required = self.remediation_p99_days + self.verification_latency_days
        if self.cure_window_days < required:
            raise CureWindowTrapError(
                f"cure window {self.cure_window_days}d < required {required}d "
                f"(remediation {self.remediation_p99_days}d + verify {self.verification_latency_days}d)"
            )
        return True


def dispatch_cure_mode(gate: CureWindowGate) -> str:
    try:
        gate.verify()
    except CureWindowTrapError:
        return "renegotiate-or-suspend"
    return "cure-enforceable"
