<?php
declare(strict_types=1);
require __DIR__.'/bootstrap.php';$p=json_decode((string)file_get_contents($runtime.'/private-retention.json'),true);$check(($p['marker']??'')===$marker&&($p['tenant']??0)===$tenant,'Exact retention context');$uid=(int)$p['user_id'];$sid=(int)$p['staff_id'];
$u=$query('SELECT * FROM yoshop_user WHERE user_id=? AND store_id=? AND nick_name=?',[$uid,$tenant,$marker.'_USER']);$s=$query('SELECT * FROM yoshop_staff WHERE id=? AND store_id=? AND user_id=? AND name=? AND create_by=?',[$sid,$tenant,$uid,$marker.'_STAFF',$marker]);$check(count($u)===1&&count($s)===1,'Retained positive owned chain');
foreach($u[0] as $k=>$v)if(strpos($k,'balance')!==false||in_array($k,['pay_money','expend_money','points'],true))$check((float)$v===0.0,'Retained money zero');
$check(bcadd((string)$s[0]['height'],'0',2)==='0.00'&&bcadd((string)$s[0]['weight'],'0',2)==='0.00'&&(int)$s[0]['is_delete']===0,'Final Staff last-deletion state');
$weights=$query('SELECT * FROM yoshop_staff_weight WHERE staff_id=? AND store_id=? ORDER BY id',[$sid,$tenant]);$check(count($weights)===6,'Retained measurements6');$real=0;$read=0;
foreach($weights as $w){$check(in_array((int)$w['id'],$p['owned_primary_keys']['staff_weight'],true),'Exact retained weight PK');if($w['create_by']===$marker){$check((int)$w['is_delete']===1,'Real CRUD soft row retained');$real++;}else{$check($w['create_by']===$marker.'_READ'&&(int)$w['is_delete']===0,'Own read fixture');$read++;}}
$current=$query('SELECT * FROM yoshop_meal_recommend WHERE staff_id=? AND store_id=? ORDER BY id',[$sid,$tenant]);$history=$query('SELECT * FROM yoshop_meal_recommend_history WHERE staff_id=? AND store_id=? ORDER BY id',[$sid,$tenant]);$check(count($current)===1&&count($history)===8,'Retained real recommended chain');
foreach(['habit','user_weight_status','nurtition_target'] as $t)$check((int)$query('SELECT COUNT(*) n FROM yoshop_'.$t.' WHERE store_id=?',[$tenant])[0]['n']===0,'No widened input write');
$retention=['lane'=>$lane,'mode'=>'retained-owned','read_only'=>true,'business_dml'=>0,'user_rows'=>1,'staff_rows'=>1,'positive_user_staff_binding_verified'=>true,'all_money_fields_zero'=>true,'staff_after_last_delete'=>['height'=>'0.00','weight'=>'0.00','is_delete'=>0],
    'weight_real_soft_rows'=>$real,'weight_read_active_rows'=>$read,'current_recommend_rows'=>1,'history_rows'=>8,'input_readonly_three_tables_owned_zero'=>true,'ownership_each_original_row_verified'=>true,'private_runtime_state_contains_actual_reusable_ids'=>true];
echo json_encode($retention,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES),"\n";
