"""Original DTO from own physical row and independent per-lane COUNT; no B-body oracle."""
import copy,hashlib,json,re
from pathlib import Path
HERE=Path(__file__).resolve().parent
def json_numbers(v):
    if isinstance(v,dict):return {k:json_numbers(x) for k,x in v.items()}
    if isinstance(v,list):return [json_numbers(x) for x in v]
    if type(v) is float and v.is_integer():return int(v)
    return v
def oracle(source,lane):
    row=copy.deepcopy(source['nutrition'][0]);row['set_name']=source['nutrition_set'][0]['name']
    if lane=='C' and isinstance(row['create_time'],str) and re.fullmatch(r'\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.0{1,6}',row['create_time']):row['create_time']=row['create_time'].split('.')[0]
    assert row['img_path']==row['source_img_path']==row['app_img']==''
    result={'code':0,'message':'请求成功','data':{'total':source['match_count'][0]['n'],'rows':[row],'nutrition_sum':source['active_count'][0]['n']}}
    return json_numbers(result)
if __name__=='__main__':
    for lane in ['B','C']:
        path=HERE/'private-original'/lane;source=json.loads((path/'before.json').read_text());value=oracle(source,lane);target=path/'expected-before-http.json';assert not target.exists(),'Frozen expected immutable';target.write_text(json.dumps(value,ensure_ascii=False,indent=2)+'\n');target.chmod(0o600);print(json.dumps({'lane':lane,'expected_sha256':hashlib.sha256(target.read_bytes()).hexdigest(),'nutrition_sum':value['data']['nutrition_sum'],'HTTP':0}))
