#!/usr/bin/env python3
"""Verify published aggregate rows for desk log KB-REPORT-JUNE-20260822.

This script checks the first-party CSV only. It does not reconstruct the
15,200-row extract, and it is not a third-party reproduction.
"""

from __future__ import annotations

import csv
import pathlib
import sys

EXPECTED = [
    {
        "retrieval_state": "no_signed_prior",
        "invoice_minus_cogs_margin": "24.0",
        "fee_excluded_contribution": "24.0",
        "july_rerun_uses_june_pack": "0",
        "sql_artifacts": "1",
        "memo_artifacts": "0",
        "chart_artifacts": "1",
        "csv_artifacts": "0",
        "june_footnote_cited": "no",
    },
    {
        "retrieval_state": "june_pack_as_context",
        "invoice_minus_cogs_margin": "18.5",
        "fee_excluded_contribution": "18.5",
        "july_rerun_uses_june_pack": "1",
        "sql_artifacts": "1",
        "memo_artifacts": "1",
        "chart_artifacts": "2",
        "csv_artifacts": "1",
        "june_footnote_cited": "yes",
    },
]


def main() -> int:
    csv_path = pathlib.Path(__file__).with_name(
        "aggregate-KB-REPORT-JUNE-20260822.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
    print("OK: published aggregate rows match desk log KB-REPORT-JUNE-20260822.")
    return 0


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