<?php
declare(strict_types=1);require __DIR__.'/native.php';require __DIR__.'/decimal-oracle.php';ck(!file_exists($runtime.'/persistence-final.json'),'Final capture once');$own=ownSnapshot();$old=oldProtection();$guard=json_decode(file_get_contents($runtime.'/guard.json'),true);ck($old===$guard['old_protection'],'Original13 final fullrows stable');$before=$guard['own_fullrows'];
foreach(['AI_U2','STORE_S1','STORE_U1','STORE_U2','STORE_R1','STORE_P1','initial_menu','meal_order_pickup','staff_department','one_card_account_map','user_subsidy','user_gift_log'] as $key)ck($own[$key]===$before[$key],'Protected own identity/prepay/excluded surface '.$key);
foreach(['meal_order'=>'id','account_settlement'=>'settlement_id','user_balance_log'=>'log_id'] as $table=>$pk)foreach($before[$table] as $row){$matches=array_values(array_filter($own[$table],static function($r)use($pk,$row){return $r[$pk]===$row[$pk];}));ck($matches===[$row],'Old0.01/prepay complete ledger preserved '.$table);}
$new=array_values(array_filter($own['meal_order'],static function($r){return $r['remark']==='CDXCORE11S1_DIRECT_002';}));ck(count($new)===1,'Exact new0.02 one paid order');$o=$new[0];ck((int)$o['source']===4&&(int)$o['pay_status']===20&&(int)$o['order_status']===30&&(int)$o['print_status']===0,'New direct paid statuses/no print');
saveOnce('persistence-final.json',['lane'=>$lane,'own_fullrows'=>$own,'old_fullrows'=>$old,'old0.01_and_prepay_fullrows_preserved'=>true,'new_paid_order_ID'=>(int)$o['id'],'source_proof'=>sourceProof(),'HTTP'=>0,'DML'=>0,'at'=>date('c')]);echo json_encode(['lane'=>$lane,'new_order_ID'=>(int)$o['id'],'old_fullrows_stable'=>true,'HTTP'=>0,'DML'=>0]),"\n";
