<?php
declare(strict_types=1);
$argv[1]='green';require __DIR__.'/bootstrap.php';$p=json_decode((string)file_get_contents($runtime.'/private-retention.json'),true);$report=json_decode((string)file_get_contents($runtime.'/green-evidence.json'),true);$check($p['tenant']===$tenant&&$p['marker']===$marker,'Final owner identity');$sid=$p['staff_id'];$uid=$p['user_id'];$owned=$p['owned_primary_keys'];$fresh=$connect();$read=static function(string $t)use($fresh,$tenant,$pks):array{$s=$fresh->prepare('SELECT * FROM yoshop_'.$t.' WHERE store_id=? ORDER BY '.$pks[$t]);$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;};$rows=[];foreach($pks as $t=>$pk)$rows[$t]=$read($t);$counts=array_map('count',$rows);$check($counts===['user'=>1,'staff'=>1,'athlete_master'=>2,'athlete_pal'=>10,'health'=>1],'Final exact five-table counts');foreach($rows as $t=>$records)foreach($records as $r)$check(in_array((int)$r[$pks[$t]],$owned[$t],true),'Final exact known PK '.$t);
$u=$rows['user'][0];$s=$rows['staff'][0];$check((int)$u['user_id']===$uid&&$u['nick_name']===$marker.'_USER','Own User marker');foreach($u as $k=>$v)if(strpos($k,'balance')!==false||in_array($k,['pay_money','expend_money','points'],true))$check((float)$v===0.0,'Final User money0');$check((int)$s['id']===$sid&&(int)$s['user_id']===$uid&&$s['name']===$marker.'_STAFF'&&$s['create_by']===$marker&&(int)$s['staff_type']===2&&(int)$s['gender']===1,'Own Staff complete chain/type/gender');$check(date('Y-m-d',strtotime((string)$s['birthday']))==='1990-01-01'&&bcadd((string)$s['height'],'0',2)==='170.00'&&bcadd((string)$s['weight'],'0',2)==='60.00','Final fixture unchanged physical demographics');
$clock=$query($dm?'SELECT CURRENT_TIMESTAMP n FROM DUAL':'SELECT CURRENT_TIMESTAMP n')[0]['n'];$offset=strtotime((string)$clock)-time();$check(abs($offset)<=3,'Native DB clock/client datetime meaning differs; do not mask a timezone shift');$window=static function($value,string $phase)use($p,$check):void{$t=$p['responses']['PILOT_CF_'.$phase];$epoch=strtotime((string)$value);$check($epoch!==false&&$epoch>=$t['start']-2&&$epoch<=$t['end']+2,'Original DATETIME HTTP window '.$phase);};
foreach($rows['athlete_master'] as $i=>$r){$input=$p['master_inputs'][$i];$id=(int)$r['id'];$phase=$i===0?'CONFIG_CREATE':'CONFIG_REPEAT_CREATE';$check($id===$p['master_ids'][$i]&&$r['staff_id']===(string)$sid&&$r['create_by']===$marker&&$r['notes']===$input['notes']&&(int)$r['store_id']===$tenant&&(int)$r['is_delete']===0,'Final complete master ownership/text/default');foreach(['sport_id','start_age','end_age','gender'] as $k)$check((int)$r[$k]===$input[$k],'Final original master integer '.$k);$check($r['sport_event_id']===implode(',',$input['sport_event_id']),'Final master actual CLOB CSV');$window($r['create_time'],$phase);$window($r['update_time'],$phase);$children=[];foreach($rows['athlete_pal'] as $v)if((int)$v['master_id']===$id)$children[]=$v;$check(count($children)===5,'Final five PAL per exact master');foreach($children as $j=>$v){$check((int)$v['master_id']===$id&&$v['staff_id']===(string)$sid&&$v['create_by']===$marker&&(int)$v['store_id']===$tenant&&(int)$v['is_delete']===0,'Final original child FK/owner/default');foreach(['sport_id','start_age','end_age','gender'] as $k)$check((int)$v[$k]===$input[$k],'Final mirrored child integer '.$k);$check($v['sport_event_id']===implode(',',$input['sport_event_id'])&&(int)$v['strength']===$input['pal_con'][$j]['strength']&&bcadd((string)$v['pal'],'0',2)===$input['pal_con'][$j]['pal'],'Final actual PAL precision/strength/CSV');$window($v['create_time'],$phase);$window($v['update_time'],$phase);}}
$h=$rows['health'][0];$check((int)$h['staff_id']===$sid&&(int)$h['health']===5&&(int)$h['store_id']===$tenant&&(int)$h['is_delete']===0&&$h['create_by']===$marker,'Final active health5 exact original');$window($h['create_time'],'HEALTH_RETAIN');$window($h['update_time'],'HEALTH_RETAIN');
$report['independent_final_original']=['fresh_counts'=>$counts,'exact_all_PK_and_user_staff_master_pal_health_ownership_verified'=>true,'all_business_original_columns_and_clob_values_verified'=>true,'business_datetime_HTTP_windows_verified'=>true,'native_DB_clock_offset_within_three_seconds'=>true,'config_response_id_zero_preserved'=>true,'actual_health_old_relation_physical_delete_verified'=>true,'user_money_zero_and_staff_demographics_unchanged'=>true,'read_only_green_DML_zero'=>true];file_put_contents($runtime.'/green-evidence.json',json_encode($report,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE));echo json_encode(['lane'=>$lane,'final_original_all_fields'=>true,'fresh_counts'=>$counts,'DB_clock_offset_seconds'=>$offset]),"\n";
