<?php
declare(strict_types=1);
namespace app\store\model\staff{class Staff{public static function detail($id){return ['id'=>$id];}}}
namespace app\store\model{class ConfigEnum{public static function getEnum($type){return [['enum_key'=>'1','enum_pid'=>0,'enum_name'=>'CDX parent'],['enum_key'=>'2','enum_pid'=>1,'enum_name'=>'CDX child']];}}}
namespace app\store\model\nutrition{class NutritionLack{public static function getAllData($where){return [['type'=>11,'reference_id'=>2]];}}}
namespace app\store\service\store{class User{public static function getLoginUserId(){return 77;}}}
namespace app\common\model\nurtition{class NutritionMeals{public static $row=[];public static function getOne($where){return self::$row;}}}
namespace {
 $base=$argv[1]??dirname(__DIR__,4).'/zhctproject/ai_api';$candidate=$argv[2]??$base;define('TP_ENV','poc');define('BUSINESS','aizhct');define('ENTERPRISE_NO','10001');require $base.'/vendor/autoload.php';spl_autoload_register(static function($c)use($base,$candidate){foreach(['app\\'=>'app/','cores\\'=>'cores/'] as $p=>$d)if(strpos($c,$p)===0){$r=$d.str_replace('\\','/',substr($c,strlen($p))).'.php';$f=is_file($candidate.'/'.$r)?$candidate.'/'.$r:$base.'/'.$r;if(is_file($f))require $f;}},true,true);
 $app=new \think\App($base);$app->setEnvName('poc');$rt=sys_get_temp_dir().'/cdx-ai-food-contract-'.getmypid().'/';mkdir($rt,0700,true);$app->setRuntimePath($rt);$app->initialize();\think\App::$store_id=2147001111;
 class FoodMysql extends \think\db\connector\Mysql{public static $IO=0;public function getFields(string $table):array{return [];}protected function createPdo($a,$b,$c,$d){self::$IO++;throw new \RuntimeException('No PDO');}public function getPDOStatement(string $sql,array $bind=[],bool $master=false,bool $procedure=false):\PDOStatement{self::$IO++;throw new \RuntimeException('No SQL');}public function getBuilderClass():string{return \think\db\builder\Mysql::class;}}
 class FoodDm extends \app\common\database\Dm{public static $IO=0;public function getFields(string $table):array{return [];}protected function createPdo($a,$b,$c,$d){self::$IO++;throw new \RuntimeException('No PDO');}public function getPDOStatement(string $sql,array $bind=[],bool $master=false,bool $procedure=false):\PDOStatement{self::$IO++;throw new \RuntimeException('No SQL');}}
 class FoodMaster extends \think\Model{}
 $cfg=$app->config->get('database');$mysql=$cfg['connections']['mysql'];$mysql['type']='\\FoodMysql';$dm=$mysql;$dm['type']='\\FoodDm';$cfg['connections']=['mysql'=>$mysql,'dm'=>$dm];
 $n=0;$fail=[];$must=static function($ok,$label)use(&$n,&$fail){$n++;if(!$ok)$fail[]=$label;};
 $vectors=[
  [['food_Intolerance'=>'UPPER','food_intolerance'=>'LOWER'],'UPPER'],
  [['food_intolerance'=>'LOWER'],'LOWER'],
  [['food_Intolerance'=>'','food_intolerance'=>'LOWER'],''],
  [['food_Intolerance'=>null,'food_intolerance'=>'LOWER'],''],
  [[], ''],
  [['food_intolerance'=>'0'],'']
 ];
 foreach(['mysql','dm'] as $engine){$cfg['default']=$engine==='mysql'?'dm':'mysql';$app->config->set($cfg,'database');$app->db->setConfig($app->config);$app->db->connect('mysql',true);$app->db->connect('dm',true);
  foreach(['model','array'] as $container)foreach($vectors as $i=>$v){$master=array_merge(['other_text'=>'other','food_allergy'=>'allergy','food_disable'=>'disable'],$v[0]);$object=$container==='model'?(new FoodMaster($master))->setConnection($engine):$master;\app\common\model\nurtition\NutritionMeals::$row=$object;$service=new \app\store\service\investigate\NutritionLack;$out=$service->foodDetail(42,'2031-04-05');$expected=$container==='model'&&$engine==='dm'?$v[1]:(empty($master['food_Intolerance'])?'':$master['food_Intolerance']);$label=$engine.'/'.$container.'/'.$i;$must($out['food_Intolerance']===$expected,$label.':original-key precedence/actual-model-only DM fallback');$must($out['other_text']==='other'&&$out['food_allergy']==='allergy'&&$out['food_disable']==='disable',$label.':other original fields');$must($out['food'][0]['checked']===['2'],$label.':original VARCHAR enum key preserved');$must(($container==='model'?$object->getData():$object)===$master,$label.':raw input unchanged');$must(!array_key_exists('food_intolerance',$out),$label.':output key unchanged');}
 }
 $must(FoodMysql::$IO===0&&FoodDm::$IO===0,'No PDO/SQL/writes');
 echo json_encode(['assertions'=>$n,'failures'=>$fail,'actual_service'=>true,'only_read_dependencies_stubbed'=>true,'SQL'=>0,'PDO'=>0,'HTTP'=>0,'DML'=>0]),"\n";exit($fail?1:0);
}
