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

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

from __future__ import annotations

import csv
import pathlib
import sys

EXPECTED = [
    {
        "retrieval_state": "faq_only",
        "sales_faq_margin_pct": "24.0",
        "finance_fee_excluded_pct": "24.0",
        "labeled_pair_shown": "no",
        "sql_artifacts": "1",
        "memo_artifacts": "0",
        "chart_artifacts": "0",
        "csv_artifacts": "0",
        "analysis_passages": "0",
    },
    {
        "retrieval_state": "bound_analysis",
        "sales_faq_margin_pct": "24.0",
        "finance_fee_excluded_pct": "18.5",
        "labeled_pair_shown": "yes",
        "sql_artifacts": "1",
        "memo_artifacts": "1",
        "chart_artifacts": "2",
        "csv_artifacts": "1",
        "analysis_passages": "3",
    },
]


def main() -> int:
    csv_path = pathlib.Path(__file__).with_name("aggregate-KB-AIKB-FAQ-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-AIKB-FAQ-20260822.")
    return 0


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