#!/usr/bin/env python3
"""Offline synthetic reviewer worksheet; no network, secrets, cookies, or targets.

Each input is an asserted reviewer field, not proof of authorization or security.
"""

CASES = (
    ("tenant-availability-a", True, "tenant", "tenant", "none", "minimal", True, "INCLUDE"),
    ("tenant-availability-b", True, "tenant", "tenant", "none", "minimal", True, "INCLUDE"),
    ("payment-preview", True, "tenant", "payment-adjacent", "none", "minimal", True, "EXCLUDE"),
    ("export-report", True, "tenant", "tenant", "action-control", "minimal", True, "EXCLUDE"),
    ("personal-profile", True, "tenant", "personal", "none", "minimal", True, "HOLD"),
    ("cookie-only-dashboard", False, "tenant", "tenant", "none", "minimal", True, "HOLD"),
)


def decide(target_scope, owner, data_class, side_effect, retention, criterion):
    """Return a conservative trial decision for asserted synthetic evidence.

    target_scope: exact written authority for this view/purpose/window/limit.
    owner: asserted organizational or tenant ownership (not grant authority).
    data_class: public, tenant, personal, payment-adjacent, or unknown.
    side_effect: none, action-control, writes, or unknown.
    retention: minimal only means an approved redacted retention plan.
    criterion: True only means a prewritten decision-changing check exists.
    """
    # Chosen conservative trial policy: explicit exclusions outrank evidence gaps.
    if data_class == "payment-adjacent" or side_effect in ("writes", "action-control"):
        return "EXCLUDE"
    if target_scope is not True:
        return "HOLD"
    if owner not in ("org", "tenant") or data_class not in ("public", "tenant"):
        return "HOLD"
    if side_effect != "none" or retention != "minimal" or criterion is not True:
        return "HOLD"
    return "INCLUDE"


def self_test():
    """Exercise ordinary decisions, unknown values, and exclusion precedence."""
    for name, *fields, expected in CASES:
        actual = decide(*fields)
        assert actual == expected, (name, actual, expected)
    assert decide(True, "tenant", "unknown", "none", "minimal", True) == "HOLD"
    assert decide(True, "tenant", "tenant", "unknown", "minimal", True) == "HOLD"
    assert decide(False, "unknown", "payment-adjacent", "unknown", "unsafe", False) == "EXCLUDE"
    assert decide(False, "unknown", "tenant", "action-control", "unsafe", False) == "EXCLUDE"


def main():
    self_test()
    print("SYNTHETIC OFFLINE TRIAL-SCOPE WORKSHEET")
    print("case\ttarget-scope\towner\tclass\tside-effect\tretention\tcriterion\tdecision")
    for name, *fields, expected in CASES:
        actual = decide(*fields)
        print("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % ((name,) + tuple(fields) + (actual,)))
    print("PASS: six ledger cases plus unknown and exclusion-precedence self-tests.")
    print("Reviewer assertions only; not actual permission or security validation.")


if __name__ == "__main__":
    main()
