# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-bound-notice-obligations-so-actual-knowledge-does-not-precede-formal-notice.md
# Remnant Warrant:    https://corpusfetch.com/c/how-must-an-instance-bound-notice-obligations-so-actual-knowledge-does-not-precede-formal-notice.warrant.json
# Markdown SHA-256:   c5dafaf92aa5e5385a7df0b42405a7b41c661be27892ac930fbd98974e75d519
# Code AST SHA-256:   3a10d7d6f6c27f69a195fa51d7e01e58191b8e936c7dc15c1b9d7090b4208e09
# Verified Classes:   BackdatedClockError, NoticeGate
# Defensive Guards:   1 fail-closed invariants (zero external deps)

from dataclasses import dataclass


class BackdatedClockError(RuntimeError):
    """Raised when a notice could be reconstructed to a deadline earlier than the instance's formal notice."""


@dataclass(frozen=True)
class NoticeGate:
    deadline_days: int
    days_to_notice: int
    days_to_earliest_constructive_knowledge: int
    obligation_response_days: int

    def verify(self) -> bool:
        reconstructed_deadline = self.days_to_earliest_constructive_knowledge + self.deadline_days
        margin = reconstructed_deadline - self.obligation_response_days - self.days_to_notice
        if margin < 0:
            raise BackdatedClockError(
                f"notice at day {self.days_to_notice} exceeds reconstructed deadline "
                f"day {reconstructed_deadline - self.obligation_response_days}"
            )
        return True


def dispatch_notice_mode(gate: NoticeGate) -> str:
    try:
        gate.verify()
    except BackdatedClockError:
        return "send-immediately-with-timestamped-trigger"
    return "notice-timely"
