ALLOWED={"REJECT","HOLD","HYBRID_APPROVED","NATIVE_APPROVED"}
MISSING={"UNKNOWN","DISPUTED","STALE","MISSING","UNPROVEN",None,""}

def decide(c):
    decisive=[c.get("pwa_evidence_ref"),c.get("web_support_state"),c.get("fallback_quality"),c.get("native_capability_delta"),c.get("evidence_ref")]
    if any(x in MISSING for x in decisive): return "HOLD"
    if c.get("distribution_channel") in {"APP_STORE","APP_STORE_AND_MANAGED"} and (c.get("store_policy_dependency") in MISSING or c.get("release_review_dependency") in MISSING): return "HOLD"
    if c.get("security_boundary") in MISSING or c.get("privacy_permission_surface") in MISSING: return "HOLD"
    if c.get("ongoing_maintenance_class")=="EXTREME" or c.get("support_burden")=="EXTREME": return "HOLD"
    no_gap=(c.get("web_support_state")=="SUPPORTED" and c.get("fallback_quality")=="ACCEPTABLE" and c.get("native_capability_delta") in {"NONE_MATERIAL","NONE"})
    if no_gap: return "REJECT"
    if c.get("native_capability_delta")=="NARROW_CLOSES_GAP": return "HYBRID_APPROVED"
    if c.get("native_capability_delta")=="FULL_CLOSES_MULTIPLE_GAPS" and c.get("web_support_state") in {"UNSUPPORTED","PARTIAL"} and c.get("fallback_quality")=="UNACCEPTABLE": return "NATIVE_APPROVED"
    return "HOLD"

def invariant_checks(c):
    got=decide(c)
    approval=got in {"HYBRID_APPROVED","NATIVE_APPROVED"}
    decisive_known=all(c.get(k) not in MISSING for k in ["pwa_evidence_ref","web_support_state","fallback_quality","native_capability_delta","evidence_ref"])
    no_gap=(c.get("web_support_state")=="SUPPORTED" and c.get("fallback_quality")=="ACCEPTABLE" and c.get("native_capability_delta") in {"NONE_MATERIAL","NONE"})
    narrow=(c.get("native_capability_delta")=="NARROW_CLOSES_GAP")
    return [
      got in ALLOWED,
      bool(c.get("review_trigger")) and bool(c.get("evidence_ref")),
      (not approval) or decisive_known,
      (not approval) or (not no_gap),
      (got!="NATIVE_APPROVED") or (not narrow),
    ]

def check_case(c):
    got=decide(c); return got, got==c.get("expected")
