#!/usr/bin/env python3
"""Generate or check the deterministic attestation-boundary report."""

from __future__ import annotations

import argparse

from check import REPORT, build_report, canonical, check_report


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--check", action="store_true")
    args = parser.parse_args()
    report = build_report()
    check_report(report)
    rendered = canonical(report)
    if args.check:
        if not REPORT.is_file() or REPORT.read_bytes() != rendered:
            raise SystemExit("generated attestation-boundary report drifted")
        print(f"attestation boundary current: {report['report_sha256']}")
        return 0
    REPORT.parent.mkdir(parents=True, exist_ok=True)
    REPORT.write_bytes(rendered)
    print(f"wrote {REPORT}: {report['report_sha256']}")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
