# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/when-does-a-case-insensitive-uniqueness-constraint-hold-on-one-host-and-not-another.md
# Remnant Warrant:    https://corpusfetch.com/c/when-does-a-case-insensitive-uniqueness-constraint-hold-on-one-host-and-not-another.warrant.json
# Markdown SHA-256:   dbf1906f8e88948ff418975e53b50f3308ae5746ea3f83856bf2e883b0fcc44b
# Code AST SHA-256:   0338026f94ddd82cf01f8d699b3f876aa4090932c29259f189b9cfa69d91f440
# Verified Classes:   CaseFoldingError, CaseFoldGate
# Defensive Guards:   3 fail-closed invariants (zero external deps)

from dataclasses import dataclass


class CaseFoldingError(RuntimeError):
    """Raised when case-insensitive uniqueness depends on host- or locale-varying folding."""


@dataclass(frozen=True)
class CaseFoldGate:
    fold_function: str  # "full-casefold", "lower", "db-collation"
    locale_pinned: bool
    single_authority: bool

    def verify(self) -> bool:
        if self.fold_function == "lower":
            raise CaseFoldingError("lower() is locale-sensitive and not portable")
        if not self.locale_pinned:
            raise CaseFoldingError("collation not pinned: inherits host locale")
        if not self.single_authority:
            raise CaseFoldingError("multiple folding authorities in the write path")
        return True


def dispatch_key_strategy(gate: CaseFoldGate) -> str:
    try:
        gate.verify()
    except CaseFoldingError:
        return "folded-column"
    return "indexed-fold"
