#!/usr/bin/env python3
"""Verify published aggregate rows for desk log ADR-DAF-20260827.

This script checks the first-party CSV only. It does not reconstruct the
cash walk, and it is not a third-party audit or reproduction.
"""

from __future__ import annotations

import csv
import pathlib
import sys

EXPECTED = [
    {"item": "planned_burn", "amount": "48000"},
    {"item": "settled_inbound_cash", "amount": "41200"},
    {"item": "variance", "amount": "-6800"},
    {"item": "one_account_change_vs_prior_week", "amount": "-6100"},
]


def main() -> int:
    csv_path = pathlib.Path(__file__).with_name(
        "aggregate-ADR-DAF-20260827.csv"
    )
    with csv_path.open(newline="", encoding="utf-8") as handle:
        rows = list(csv.DictReader(handle))
    if rows != EXPECTED:
        print("FAIL: published aggregate rows do not match the desk log.", file=sys.stderr)
        return 1
    planned = int(rows[0]["amount"])
    collected = int(rows[1]["amount"])
    variance = int(rows[2]["amount"])
    if collected - planned != variance:
        print("FAIL: 41200 - 48000 does not equal published variance.", file=sys.stderr)
        return 1
    print("OK: published aggregate rows match desk log ADR-DAF-20260827.")
    return 0


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