"""Run locally: python3 validate.py. Decimal arithmetic; no model request."""
from decimal import Decimal
from pathlib import Path
import json,hashlib
P=Path(__file__).parent
def check(name):
 record=json.loads((P/name).read_text());line=record['line']
 quantity=Decimal(line['quantity']);unit=Decimal(line['unit_price']);reported=Decimal(line['line_amount'])
 expected=(quantity*unit).quantize(Decimal('0.01'));difference=(reported-expected).quantize(Decimal('0.01'))
 return {'input':name,'input_sha256':hashlib.sha256((P/name).read_bytes()).hexdigest(),'method':'Python decimal.Decimal; string inputs; two-decimal line amount','quantity':str(quantity),'unit_price':str(unit),'reported_amount':format(reported,'.2f'),'expected_amount':format(expected,'.2f'),'difference':format(difference,'.2f'),'result':'matches' if difference==0 else 'needs_review','tax_checked':False,'accounting_import_performed':False}
receipt={'example_type':'actual_local_deterministic_validation','not_a_model_result':True,'scope':'Authored sample line arithmetic only; no tax, rounding policy beyond this two-decimal fixture, or accounting import','checks':[check('reference-fields.json'),check('faulty-candidate.json')]}
assert receipt['checks'][0]['expected_amount']=='58.50' and receipt['checks'][0]['result']=='matches'
assert receipt['checks'][1]['difference']=='526.50' and receipt['checks'][1]['result']=='needs_review'
(P/'validation-receipt.json').write_text(json.dumps(receipt,indent=2)+'\n')
print(json.dumps(receipt,indent=2))
