"""Synthetic abstention accounting fixture; not production evidence."""
import json


def report(total, answered, wrong):
    counts = (total, answered, wrong)
    if any(type(n) is not int for n in counts):
        raise ValueError("counts must be integers")
    if not 0 <= wrong <= answered <= total or total == 0:
        raise ValueError("require 0 <= wrong <= answered <= total > 0")
    return {
        "coverage": answered / total,
        "selective_risk": wrong / answered if answered else None,
        "escalations": total - answered,
    }


def main():
    broad = report(1000, 900, 45)
    cautious = report(1000, 400, 4)
    assert broad == {"coverage": 0.9, "selective_risk": 0.05, "escalations": 100}
    assert cautious == {"coverage": 0.4, "selective_risk": 0.01, "escalations": 600}
    assert report(10, 0, 0) == {"coverage": 0.0, "selective_risk": None, "escalations": 10}
    assert report(10, 10, 0)["escalations"] == 0
    for args in [(0, 0, 0), (10, 11, 0), (10, 2, 3), (10, -1, 0), (10.0, 1, 0), (True, 1, 0)]:
        try:
            report(*args)
        except ValueError:
            pass
        else:
            raise AssertionError(f"accepted invalid counts: {args}")
    print(json.dumps({"broad": broad, "cautious": cautious, "assertions": "passed"}, indent=2))


if __name__ == "__main__":
    main()
