<?php
declare(strict_types=1);
// Independent physical-row projection and literal source contract; no response-derived expectations.
function baseline():array{global $runtime;$r=json_decode(file_get_contents($runtime.'/prepared-owned-rows.json'),true)['rows']['user'][0];$cols=json_decode(file_get_contents($runtime.'/schema.json'),true)['user']['columns'];$out=[];foreach($cols as $c){$k=strtolower($c['column_name']);if(in_array($k,['is_delete','store_id','create_time','update_time'],true))continue;$v=$r[$k];if(in_array($k,['balance','withdrawable_balance','activity_principal_balance','subsidy_balance','gift_balance','pay_money','expend_money'],true))$v='0.00';$out[$k]=$v;}$out['passwordStatus']=2;$out['needChangePassword']=0;$out['password_updated_at']=1;$out['hide_mobile']='000****9992';return $out;}
function rowDTO($manual):array{return ['date'=>1791648000,'height'=>$manual?'181.25':'180.25','weight'=>$manual?'72.34':'72.5','bmi'=>$manual?'22.02':'22.31','dateFmt'=>'2026-10-11'];}
function expectDTO($label,$snapshot,$clock):array{global $runtime;$base=baseline();switch($label){case 'W1_MANUAL':return array_merge($base,['weight'=>'72.34','existScore'=>0]);case 'W2_GOAL':return array_merge($base,['user_id'=>actor()['user_id'],'store_id'=>10001,'start_date'=>1791648000,'initial_weight'=>72.5,'target_weight'=>'71.50','adjust_speed'=>2,'status'=>3,'end_date'=>1792771200]);case 'R1_MANUAL_ROWS':return [rowDTO(true)];case 'R2_GOAL_ROWS':return [rowDTO(false)];case 'R3_INFO':return ['date'=>'2026-10-11','height'=>'180.25','weight'=>'72.5','bmi'=>'22.31','weight_echarts'=>[rowDTO(false)],'status'=>3,'initial_weight'=>'72.5','start_date'=>'2026-10-11','dayDiff'=>(int)ceil(($clock-1791648000)/86400),'target_weight'=>'71.50','end_date'=>'2026-10-24','diffWeight'=>0,'adjust_speed'=>2,'target_flag'=>1,'tip'=>'计划每周减重0.5kg','percent'=>0,'bmi_cn'=>'标准'];case 'R4_GOAL_INFO':return ['start_date'=>'2026-10-11','initial_weight'=>'72.5'];case 'R5_STATUS_EXISTING_GOAL':$r=$snapshot['user_weight_status'][0];$cols=json_decode(file_get_contents($runtime.'/schema.json'),true)['user_weight_status']['columns'];$out=[];foreach($cols as $c){$k=strtolower($c['column_name']);if(!in_array($k,['create_time','update_time'],true))$out[$k]=$r[$k];}return array_merge($out,['start_date_fmt'=>'2026-10-11','end_date_fmt'=>'2026-10-24','current_status'=>1,'latest_weight'=>'72.5','latest_date'=>'2026-10-11','finish_status'=>1,'total_days'=>0,'huashu'=>'累计0天体重保持在72.5公斤']);case 'R6_DATES_NONEMPTY':return ['list'=>['2026-10-11']];}throw new RuntimeException('Unknown DTO case');}
function checkDTO($label,$record,$snapshot){$d=json_decode($record['raw_response_body'],true,512,JSON_THROW_ON_ERROR);ck(array_keys($d)===['status','message','data','trace_id']&&$record['http_status']===200&&$d['status']===200&&$d['message']==='success'&&is_string($d['trace_id'])&&preg_match('/^[0-9a-f]{13}$/D',$d['trace_id']),'Exact whole original envelope');$want=expectDTO($label,$snapshot,(int)$record['business_start']);ck(json_encode($d['data'],JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)===json_encode($want,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES),'Complete ordered typed DTO '.$label);saveOnce('oracle-'.$label.'.json',['expected_data'=>$want,'full_typed_ordered_DTO'=>true,'envelope'=>true]);}
