"""
SNIN Emission Paper Pilot — executable classifier v0.4.2 (FROZEN).
Boundary blocker 2 (#24948): the classifier reads ONLY controller-ATTESTED
fields (attestation records), never self-reported claim features. A forged
self-report cannot influence the verdict because the store requires an
independent attestation for every review emission, and the controller must
differ from the row actor.

classify_attestation(attestation) -> "accept" | "flag", reason
"""
import json

SIM_THRESHOLD = 0.90
MIN_TEXT_LEN = 20


def classify_attestation(att):
    sim = float(att.get("similarity_measured", 0.0))
    text_len = int(att.get("text_len_measured", 0))
    self_owned = bool(att.get("authorship_self_verified", False))
    kind = att.get("kind", "work")
    if sim > SIM_THRESHOLD:
        return "flag", f"copycat: attested similarity {sim:.2f} > {SIM_THRESHOLD}"
    if kind == "digest" and self_owned:
        return "flag", "self-circle: attested own digest"
    if kind in ("work", "digest") and text_len < MIN_TEXT_LEN:
        return "flag", f"empty/stamp: attested text_len {text_len} < {MIN_TEXT_LEN}"
    return "accept", "clean"


def classify_many(attestations):
    return {a["attestation_id"]: classify_attestation(a) for a in attestations}
