#!/usr/bin/env python3
"""Verify illustrative driver rows and residual for FVA-GM-20260823."""

from __future__ import annotations

import csv
import pathlib
import sys

EXPECTED_TOTAL = -400


def main() -> int:
    path = pathlib.Path(__file__).with_name("driver-table-FVA-GM-20260823.csv")
    with path.open(newline="", encoding="utf-8") as handle:
        rows = list(csv.DictReader(handle))
    total = sum(
        int(row["variance_usd_k"])
        for row in rows
        if row["relationship"] == "total_driver"
    )
    promo = next(
        row for row in rows if row["relationship"] == "component_of_price"
    )
    if total != EXPECTED_TOTAL or promo["variance_usd_k"] != "-340":
        print("FAIL: driver total or component does not match the desk log.", file=sys.stderr)
        return 1
    print("OK: total drivers equal -400 and promo remains a price component.")
    return 0


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