# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-a-gdpr-erasure-request-as-a-tombstone-consistency-problem-rather-than-a-row-delete-the-ann-index-resurrection.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-a-gdpr-erasure-request-as-a-tombstone-consistency-problem-rather-than-a-row-delete-the-ann-index-resurrection.warrant.json
# Markdown SHA-256:   96dec5f55018b3d0e5cdb21d3ca252839282e908c1c2a8e0716f02124907766f
# Code AST SHA-256:   fa15466fea381d33487dc92df809087657bfbd1887545de7786e6996fd6f5cb6
# Verified Classes:   ErasureState, TombstoneResurrectionError, IndexRecord
# Defensive Guards:   5 fail-closed invariants (zero external deps)

from dataclasses import dataclass
from enum import Enum


class ErasureState(Enum):
    LIVE = "live"
    TOMBSTONED = "tombstoned"   # logically deleted, physically present
    ERASED = "erased"           # compaction confirmed, coordinates gone


class TombstoneResurrectionError(RuntimeError):
    """Raised when a receipt would certify erasure the index has not reached."""


@dataclass
class IndexRecord:
    subject_id: str
    state: ErasureState
    payload_inline: bool
    compaction_watermark: int


def issue_erasure_receipt(
    record: IndexRecord,
    current_watermark: int,
    mountable_snapshots: list[int],
    probe_returns_subject: bool,
) -> str:
    # Invariant 3/5: receipt requires physical erasure, not logical deletion.
    if record.state is ErasureState.TOMBSTONED:
        raise TombstoneResurrectionError(
            f"subject {record.subject_id} is tombstoned, not erased; "
            f"coordinates still present in index segments"
        )
    if record.state is not ErasureState.ERASED:
        raise TombstoneResurrectionError(
            f"subject {record.subject_id} in state {record.state.value}; "
            f"cannot certify erasure"
        )
    # Invariant 5: compaction watermark must have advanced past the delete.
    if current_watermark < record.compaction_watermark:
        raise TombstoneResurrectionError(
            f"compaction watermark {current_watermark} predates required "
            f"{record.compaction_watermark}; forced compaction incomplete"
        )
    # Invariant 4: no reachable snapshot may predate the erasure.
    stale = [s for s in mountable_snapshots if s < record.compaction_watermark]
    if stale:
        raise TombstoneResurrectionError(
            f"mountable snapshots {stale} predate erasure; auditor replay "
            f"would reconstruct subject {record.subject_id}"
        )
    # Invariant 3: adversarial probe must return nothing for the subject.
    if probe_returns_subject:
        raise TombstoneResurrectionError(
            f"probe query still surfaces subject {record.subject_id}; "
            f"traversal-path leak despite erased state"
        )
    return f"receipt:erased:{record.subject_id}:wm={current_watermark}"
