# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reject-a-gdpr-erasure-request-for-a-memory-record-that-its-own-retention-policy-has-already-scheduled-for-garbage-c.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-reject-a-gdpr-erasure-request-for-a-memory-record-that-its-own-retention-policy-has-already-scheduled-for-garbage-c.warrant.json
# Markdown SHA-256:   46e367c9d29aaf411116e289f10b909627921f162de655dc0a2bcd1a35f58565
# Code AST SHA-256:   9d18d29766bc38bba1f03eab42f312f53ec7ed57b040780119b29eeb7fad9bcf
# Verified Classes:   ErasureStateConflationError
# Defensive Guards:   2 fail-closed invariants (zero external deps)

def forget(record_id, subject_id):
    rec = store.get(record_id)
    if rec.expires_at <= now():
        return ErasureReceipt(record_id, method="ttl")  # BUG
    ...

class ErasureStateConflationError(RuntimeError):
    """Raised when a forget request would be satisfied by TTL expiry rather than an explicit erasure."""
    pass


def forget(record, subject_id, now, jurisdiction_excludes_backups=False):
    if record.state == "ERASED":
        return {"status": "already_erased", "receipt_id": record.erasure_receipt_id}
    if record.state == "LEGAL_HOLD" or record.legal_basis == "STATUTORY_RETENTION":
        return {"status": "refused", "reason": "statutory_retention", "citation": record.legal_basis_ref}
    if record.data_subject_id != subject_id:
        raise ErasureStateConflationError(
            f"record {record.id} belongs to a different subject; TTL expiry is not in scope"
        )
    if record.expires_at <= now and not jurisdiction_excludes_backups:
        raise ErasureStateConflationError(
            f"record {record.id} is LIVE+expired; TTL path does not purge backups or replicas. "
            "Promote to explicit erasure."
        )
    record.state = "ERASING"
    job = enqueue_backup_purge(record.id)
    broadcast_erase_to_replicas(record.id)
    receipt = issue_receipt(record.id, subject_id, method="explicit", backup_job=job.id)
    return {"status": "erased", "receipt_id": receipt.id}
