"""Illustrative status classification, not a Relay implementation.

Run: python status_from_operation_example.py
Invented records only. No network, database, model, or external dependency.
This example code is Apache-2.0; see the SPIRALMESH software license.
"""
import json


def previous(recipient, requires_human=False, message_type="coordination"):
    return "AWAITING_HUMAN" if recipient == "THE_BRIDGE" else "QUEUED"


def classify(recipient, requires_human=False, message_type="coordination"):
    if recipient != "THE_BRIDGE":
        return "QUEUED"
    decision_requested = requires_human or message_type == "decision_request"
    return "AWAITING_HUMAN" if decision_requested else "DELIVERED"


def main():
    cases = [
        ("Informational human message", "THE_BRIDGE", False, "coordination", "DELIVERED"),
        ("Explicit decision flag", "THE_BRIDGE", True, "coordination", "AWAITING_HUMAN"),
        ("Decision request type", "THE_BRIDGE", False, "decision_request", "AWAITING_HUMAN"),
        ("Other recipient still queued", "EXAMPLE_PARTICIPANT", False, "coordination", "QUEUED"),
    ]
    rows = []
    for name, recipient, flag, kind, expected in cases:
        old, new = previous(recipient, flag, kind), classify(recipient, flag, kind)
        assert new == expected, name
        rows.append({"case": name, "old": old, "new": new, "expected": expected})
    assert rows[0]["old"] != rows[0]["expected"]
    assert rows[2]["new"] == "AWAITING_HUMAN"
    result = {
        "invented_records": True, "checks_passed": len(rows), "old_bug_reproduced": True,
        "cases": rows,
        "limit": "Classification only. Real DELIVERED requires actual mailbox storage; this script stores nothing. No read, approval, completion or identity is established.",
    }
    print(json.dumps(result, indent=2))


if __name__ == "__main__":
    main()
