#!/usr/bin/env python3
"""Accept the real repaired nutrition BIFF export; retain original 190 red evidence."""
import hashlib
import json
import subprocess
from pathlib import Path
import integrate_20261010 as tool
from integrate_20261011_batches46_48 import item

HERE = Path(__file__).resolve().parent
PRIVATE = tool.ROOT.parent.parent / 'local/dm8-store-purchase-read3-20261012.L5dTYR/stage3/food-nutrition-export192-20261013'
BASE = 'work_store/apifox/2026-09-30-dm8-interface-acceptance/parallel-nutrition-xls-20261013/'


def verify():
    for name, digest in [
        ('REPORT.md', '97dd3303f016eae474d513e2ae277f1ca6db5f4e11143f87a21cad956dbc0729'),
        ('manifest.json', 'cbcd271a4ac7623ec2320ad65e53d2b97a19b5577e010aa7309c8ff40263ed90'),
        ('verify.py', '1f06a3b0ac2117607c045fc839c17820e0c2f6fe3b9aedf3df86f4a21ff01305'),
        ('source192.json', 'b4917ec51fb5242426e3c6aa4563ca09e4f4b38f4da76b96edf84cb18201aec9'),
    ]:
        assert hashlib.sha256((PRIVATE / name).read_bytes()).hexdigest() == digest
    r = json.loads(subprocess.check_output(['python3', str(PRIVATE / 'verify.py')]))
    assert r['checks'] == 695531 and r['assets'] == 104
    assert r['business_HTTP'] == r['health_HTTP'] == 2
    assert r['B_rows'] == 5465 and r['C_rows'] == 2009
    assert r['B_cells'] == 125679 and r['C_cells'] == 46233
    assert r['own_21_zero_cells_equal'] and r['DML_DDL_txn_external'] == 0
    assert hashlib.sha256((tool.source_root('store') / 'application/model/Dishes.php').read_bytes()).hexdigest() == '11e4b93775c2a751b49eb40f34952b3a2bfbfb3e8c997163fa5ccbcf8d8ee577'


if __name__ == '__main__':
    audit = HERE / 'integration-20261013-batch192.json'
    assert not audit.exists()
    specs = [item('store', 'GET', '/p/restaurant/foodNutritionExport', BASE,
        readback='tested-pass-independent-5465-and-2009-source-rows-to-real-BIFF-cells-and-types',
        success_case='partial-evidence-owned-21-zero-cells-equal-and-full-current-active-sample',
        parity='partial-evidence-each-source-verified-original-BIFF-types-zero-not-empty',
        boundary_empty_min_max='partial-evidence-B-real-zero-weight-NULL-C-own-zero-nutrients-native-probe-C-zero-weight-unobserved',
        cleanup='own-workers-token-cache-tmp-zero-readonly-protected-scope-unchanged')]
    tool.main(specs, audit, verify)
