<?php
namespace app\cores\database { class Dm {} }
namespace {
function config($key){return $GLOBALS['database_type'];}
function getImgFullPath($path='',$exist=false){return $path?'media:'.$path:'';}
class ListRows {
 public $rows=[],$connection;
 public function inquiryCount(...$args){return count($this->rows);}
 public function inquiryNutrition(...$args){return $this->rows;}
 public function db($unused=false){return $this;}
 public function getConnection(){return $this->connection;}
}
$root=$argv[1];require $root.'/application/common/service/NutritionFloat82Write.php';require $argv[2]??$root.'/application/p/logic/Nutrition.php';require $argv[3]??$root.'/application/m/logic/Nutrition.php';
$p=(new \ReflectionClass(\app\p\logic\Nutrition::class))->newInstanceWithoutConstructor();$m=(new \ReflectionClass(\app\m\logic\Nutrition::class))->newInstanceWithoutConstructor();$model=new ListRows();
foreach([$p,$m]as $logic){$prop=new \ReflectionProperty($logic,'model');$prop->setAccessible(true);$prop->setValue($logic,$model);}
$source=json_decode(file_get_contents($root.'/tests/Nutrition/Float82SourceOracles.json'),true);$checks=0;$failures=[];
foreach(['mysql','app\\cores\\database\\Dm']as $type){$GLOBALS['database_type']=$type;$model->connection=$type==='mysql'?new \stdClass():new \app\cores\database\Dm();
 foreach($source['cases']as $case){if(strpos($case['case_id'],'ORACLE-')!==0||$case['expected_stored_double_hex']===null)continue;
  $physical=unpack('e',hex2bin($case['expected_stored_double_hex']))[1];$getter=unpack('e',hex2bin($case['expected_direct_getter_hex']))[1];
  foreach(['power','carbohydrate','protein','fat','sodium']as $field){
   $row=['id'=>1,'uuid'=>'OWN-LIST','name'=>'CDXOWN-LIST','create_time'=>'2001-01-01 01:01:01','img_path'=>'','source_img_path'=>'','app_img'=>'','use_weight'=>$physical,$field=>$type==='mysql'?$getter:$physical];$model->rows=[$row];
   foreach(['p'=>$p,'m'=>$m]as $label=>$logic){$data=$logic->lists(['is_del'=>1],1,1,[],['a.*'])['data'];$out=$data['rows'][0];$checks++;if($out[$field]!==$getter)$failures[]=['consumer'=>$label,'type'=>$type,'field'=>$field,'source_case'=>$case['case_id'],'actual_hex'=>bin2hex(pack('e',$out[$field])),'source_getter_hex'=>$case['expected_direct_getter_hex']];$checks++;if($out['use_weight']!==$physical)throw new \RuntimeException('Unrelated field changed');}
  }
 }
}
$variant=$argv[4]??'red';if(!in_array($variant,['red','candidate'],true))throw new \RuntimeException('Evidence variant');$result=['status'=>$failures?'RED_LISTS':'GREEN_LISTS','variant'=>$variant,'assertions'=>$checks,'differences'=>count($failures),'failures'=>$failures,'HTTP'=>0,'DML'=>0,'DB_connections'=>0,'scope'=>'Actual p/m logic, injected original PDO row shapes; source-backed pure test only'];file_put_contents(__DIR__.'/lists-float82-'.$variant.'.json',json_encode($result,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT));unset($result['failures']);echo json_encode($result),"\n";exit($failures?2:0);
}
