<?php
declare(strict_types=1);
require __DIR__.'/bootstrap.php';$p=json_decode((string)file_get_contents($runtime.'/private-retention.json'),true);$report=json_decode((string)file_get_contents($runtime.'/report.json'),true);$check($p['marker']===$marker&&$p['tenant']===$tenant,'Final own context');$owned=$p['owned_primary_keys'];$fresh=$connect();$read=static function(string $table)use($fresh,$tenant):array{$s=$fresh->prepare('SELECT * FROM yoshop_'.$table.' WHERE store_id=? ORDER BY '.($table==='delivery'?'delivery_id':'rule_id'));$s->execute([$tenant]);$out=$s->fetchAll(PDO::FETCH_ASSOC);foreach($out as &$r)foreach($r as &$v)if(is_resource($v))$v=stream_get_contents($v);unset($r,$v);return $out;};$parents=$read('delivery');$children=$read('delivery_rule');$check(count($parents)===2&&count($children)===3,'Final independent parent/child count');$window=static function($epoch,string $scenario)use($p,$check):void{$t=$p['responses']['PILOT_DL_'.$scenario];$check(is_numeric($epoch)&&(int)$epoch>=$t['start']-2&&(int)$epoch<=$t['end']+2,'Actual source Unix HTTP window '.$scenario);};$round=static function($v):string{return bcadd(bcadd((string)$v,'0.005',12),'0',2);};
foreach($parents as $row){$id=(int)$row['delivery_id'];$label=array_search($id,$p['ids'],true);$check(in_array($label,['A','B'],true)&&in_array($id,$owned['delivery'],true),'Exact parent ID');$e=$p['expected'][$label];$check($row['name']===$e['name']&&strpos($row['name'],$marker)===0,'Exact parent name marker');foreach(['method','sort','is_delete'] as $k)$check((int)$row[$k]===$e[$k],'Final parent original field '.$k);$window($row['create_time'],$label==='A'?'ADD_A_TWO_RULES':'ADD_B_ONE_RULE');$window($row['update_time'],$label==='A'?'DELETE_A_SOFT':'ADD_B_ONE_RULE');$rs=[];foreach($children as $r)if((int)$r['delivery_id']===$id)$rs[]=$r;$check(count($rs)===count($e['rules']),'Exact final child count');foreach($rs as $i=>$r){$check(in_array((int)$r['rule_id'],$owned['delivery_rule'],true)&&(int)$r['store_id']===$tenant,'Exact child own ID/store');foreach(['region','region_text'] as $k)$check(is_string($r[$k])&&json_decode($r[$k],true)===$e['rules'][$i][$k],'Final full actual JSON/CLOB '.$k);foreach(['first','additional'] as $k)$check((float)$r[$k]===(float)$e['rules'][$i][$k],'Final DOUBLE '.$k);foreach(['first_fee','additional_fee'] as $k)$check(bcadd((string)$r[$k],'0',2)===$round($e['rules'][$i][$k]),'Final metadata-scaled DECIMAL '.$k);$window($r['create_time'],$label==='A'?'EDIT_A_REPLACE_RULES':'ADD_B_ONE_RULE');}}
$check($snapshot()===$p['before'],'Final natural two-table full SHA exact owned PK exclusions');$report['independent_final_original']=['parents'=>2,'children'=>3,'all_parent_child_ids_and_ownership_verified'=>true,'all_physical_input_columns_and_clob_values_verified'=>true,'all_creation_update_unix_windows_verified'=>true,'A_soft_deleted_B_active'=>true,'child_parent_FK_independently_verified_after_commit'=>true,'natural_two_table_sha_unchanged'=>true,'old_rules_physically_deleted_by_actual_edit'=>2,'extra_physical_cleanup'=>false];file_put_contents($runtime.'/evidence.json',json_encode($report,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));echo json_encode(['lane'=>$lane,'independent_full_original_verification'=>true,'parents'=>2,'children'=>3]),"\n";
