# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-bound-indemnity-scope-to-actual-payment-capacity.md
# Remnant Warrant:    https://corpusfetch.com/c/how-must-an-instance-bound-indemnity-scope-to-actual-payment-capacity.warrant.json
# Markdown SHA-256:   ceb20edae466fa9ef70d7bdd6c1c4584268b00457572b3236b90c6ab622a160b
# Code AST SHA-256:   c5dcd75766e8c33e7dba9e3f9d8c5bb93c199d18bf9ff11af8546fb98b4ca109
# Verified Classes:   PaperIndemnityError, IndemnityGate
# Defensive Guards:   1 fail-closed invariants (zero external deps)

from dataclasses import dataclass


class PaperIndemnityError(RuntimeError):
    """Raised when an indemnity scope exceeds the indemnifying party's realizable capacity."""


@dataclass(frozen=True)
class IndemnityGate:
    indemnity_cap: float
    liquid_assets: float
    credit_facility: float
    insurance_recovery_verified: float
    gap_disclosed: bool = False

    def verify(self) -> bool:
        capacity = self.liquid_assets + self.credit_facility + self.insurance_recovery_verified
        if self.indemnity_cap > capacity and not self.gap_disclosed:
            raise PaperIndemnityError(
                f"indemnity cap {self.indemnity_cap} > capacity {capacity}: "
                f"gap {self.indemnity_cap - capacity} is undisclosed credit exposure"
            )
        return True


def dispatch_indemnity_mode(gate: IndemnityGate) -> str:
    try:
        gate.verify()
    except PaperIndemnityError:
        return "cap-by-capacity-or-disclose-gap"
    return "indemnity-realizable"
