<?php
require __DIR__.'/NativeGate.php';
$pre=json_decode(file_get_contents(__DIR__.'/private/preflight-'.(getenv('NF_LANE')?:'B').'.json'),true);$params=$pre['proposed_params'];$params['use_weight']='12.345';NFGate::$case=['path'=>'/m/nutrition/update','params'=>$params];
$sets=[];$binds=[];foreach(NFGate::$fields as $f){$sets[]=$f.'=:data__'.$f;$v=$f==='is_own'?1:$params[$f];$binds[':data__'.$f]=['value'=>$v,'php_type'=>gettype($v),'type'=>in_array($f,['use_weight','use_number','employ','is_nutrition_station','is_own'],true)?1:2,'ok'=>true];}$binds[':where_AND_uuid']=['value'=>$params['uuid'],'php_type'=>'string','type'=>2,'ok'=>true];$sql='UPDATE ydy_nutrition SET '.implode(',',$sets).' WHERE uuid = :where_AND_uuid';
NFGate::binds($sql,$binds);if(NFGate::$dml!==1)throw new RuntimeException('Positive rejected');$n=0;$fail=static function($s,$b,$path='/m/nutrition/update',$count=0)use(&$n){NFGate::$dml=$count;NFGate::$case['path']=$path;$red=false;try{NFGate::binds($s,$b);}catch(RuntimeException $e){$red=true;}if(!$red)throw new RuntimeException('Counterexample not rejected');$n++;};
$fail($sql,$binds,'/m/nutrition/info');$fail($sql,$binds,'/m/nutrition/update',1);
foreach(['name','use_weight','set_uuid','nutrition_category_uuid','is_own']as $f){$b=$binds;$b[':data__'.$f]['value']=$f==='is_own'?0:'wrong';$fail($sql,$b);}
foreach(['type','php_type','ok']as $f){$b=$binds;$b[':data__use_weight'][$f]=$f==='type'?2:($f==='php_type'?'double':false);$fail($sql,$b);}
$b=$binds;$b[':where_AND_uuid']['value']='OTHER';$fail($sql,$b);
foreach(['ydy_nutrition_set','ydy_user']as $t)$fail(str_replace('ydy_nutrition ',$t.' ',$sql),$binds);
$fail(str_replace('WHERE uuid','WHERE id',$sql),$binds);$fail($sql.' OR 1=1',$binds);$fail(str_replace('use_weight=:data__use_weight','use_weight=12.345',$sql),$binds);$fail(str_replace('use_weight=:data__use_weight','power=:data__power',$sql),$binds);$fail(str_replace('name=:data__name,','',$sql),$binds);$fail($sql.'; DELETE FROM ydy_nutrition',$binds);$fail('DELETE FROM ydy_nutrition WHERE uuid=:where_AND_uuid',$binds);$fail('INSERT INTO ydy_nutrition(name) VALUES(:data__name)',$binds);
echo json_encode(['positive'=>1,'counterexamples'=>$n,'all_rejected'=>true,'HTTP'=>0,'DML'=>0]),"\n";

