<?php
require __DIR__.'/NativeGate.php';$lane=getenv('NF_LANE');NFGate::$lane=$lane;$lease=json_decode(file_get_contents(__DIR__.'/private/lease-expected-'.$lane.'.json'),true)['source_after'];$row=array_values(array_filter($lease['nutrition'],static function($r){return $r['name']==='CDXNF11F5-candidate-product';}))[0];$n=0;$positive=0;
foreach(['12.346','123.4568']as $value){$params=['uuid'=>$row['uuid']];foreach(NFGate::$fields as $f)if($f!=='is_own')$params[$f]=$f==='use_weight'?$value:$row[$f];$case=['path'=>'/m/nutrition/update','params'=>$params];if($lane==='C')$case['C_generated_expression']=NFGate::$expressions[$value];NFGate::$case=$case;$sets=[];$binds=[];foreach(NFGate::$fields as $f){if($lane==='C'&&$f==='use_weight'){$sets[]='use_weight='.NFGate::$expressions[$value];continue;}$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::$dml=0;NFGate::binds($sql,$binds);$positive++;
$reject=static function($s,$b,$c=null,$count=0)use(&$n,$case){NFGate::$dml=$count;NFGate::$case=$c??$case;$red=false;try{NFGate::binds($s,$b);}catch(RuntimeException $e){$red=true;}if(!$red)throw new RuntimeException('Counterexample accepted');$n++;};
$c=$case;$c['path']='/m/nutrition/info';$reject($sql,$binds,$c);$reject($sql,$binds,null,1);
foreach(['name','set_uuid','nutrition_category_uuid','is_own']as $f){$b=$binds;$b[':data__'.$f]['value']=$f==='is_own'?0:'wrong';$reject($sql,$b);}
$b=$binds;$b[':where_AND_uuid']['value']='wrong';$reject($sql,$b);$b=$binds;$b[':data__use_number']['type']=2;$reject($sql,$b);
$reject(str_replace('ydy_nutrition ','ydy_nutrition_set ',$sql),$binds);$reject($sql.' OR 1=1',$binds);$reject(str_replace('WHERE uuid','WHERE id',$sql),$binds);$reject(str_replace('name=:data__name,','',$sql),$binds);$reject($sql.'; DELETE FROM ydy_user',$binds);$reject(str_replace('name=:data__name','power=:data__power',$sql),$binds);
$c=$case;$c['params']['use_weight']='12.345';$reject($sql,$binds,$c);
if($lane==='C'){$reject(str_replace(NFGate::$expressions[$value],'CAST(12.35 AS REAL)',$sql),$binds);$reject(str_replace(NFGate::$expressions[$value],':data__use_weight',$sql),$binds);$c=$case;$c['C_generated_expression']='CAST(12.35 AS REAL)';$reject($sql,$binds,$c);}
else{$b=$binds;$b[':data__use_weight']['type']=2;$reject($sql,$b);$b=$binds;$b[':data__use_weight']['value']=(float)$value;$reject($sql,$b);}
}
$r=['lane'=>$lane,'positive'=>$positive,'counterexamples'=>$n,'all_rejected'=>true,'HTTP'=>0,'DML'=>0,'PDO'=>0];echo json_encode($r),PHP_EOL;

