<?php
$runtime=__DIR__;$lane=getenv('GP_LANE');$port=$lane==='B'?18661:18662;$request=json_decode(file_get_contents($runtime.'/private-request.json'),true);$count=0;$sentCount=0;
foreach($request['cases']as $label=>$params){
 if(file_exists($runtime.'/evidence/'.$label.'.sent.json'))continue;
 file_put_contents($runtime.'/evidence/'.$label.'.sent.json',json_encode(['path'=>'/p/accountSetting/giftFlowList','params'=>$params]));chmod($runtime.'/evidence/'.$label.'.sent.json',0600);$sentCount++;
 $headers=[];$c=curl_init('http://127.0.0.1:'.$port.'/p/accountSetting/giftFlowList');curl_setopt_array($c,[CURLOPT_POST=>true,CURLOPT_POSTFIELDS=>http_build_query($params),CURLOPT_RETURNTRANSFER=>true,CURLOPT_HTTPHEADER=>['token: '.$request['token'],'X-GD-Label: '.$label],CURLOPT_CONNECTTIMEOUT=>5,CURLOPT_TIMEOUT=>30,CURLOPT_HEADERFUNCTION=>static function($c,$line)use(&$headers){if(preg_match('/^(Content-Type|X-Powered-By):/i',$line))$headers[]=$line;return strlen($line);}]);$body=curl_exec($c);$info=curl_getinfo($c);$error=curl_error($c);curl_close($c);
 $result=['HTTP'=>$info['http_code'],'body'=>$body,'body_sha256'=>hash('sha256',(string)$body),'headers'=>$headers,'curl_error'=>$error,'duration'=>$info['total_time']];file_put_contents($runtime.'/evidence/'.$label.'.result.json',json_encode($result,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));chmod($runtime.'/evidence/'.$label.'.result.json',0600);
 $wirefile=$runtime.'/evidence/'.$label.'.wire.json';if(!is_file($wirefile))throw new RuntimeException('No server native wire');$wire=json_decode(file_get_contents($wirefile),true);$count+=count($wire['prepared']);if($count>78)throw new RuntimeException('Reserve preflight/postflight within SELECT120');
 $dto=json_decode((string)$body,true);echo json_encode(['lane'=>$lane,'label'=>$label,'HTTP'=>$info['http_code'],'code'=>$dto['code']??null,'total'=>$dto['data']['total']??null,'rows'=>count($dto['data']['data']??[]),'native_queries'=>count($wire['prepared'])]),"\n";flush();
}
echo json_encode(['lane'=>$lane,'HTTP'=>$sentCount,'DML'=>0,'DDL'=>0,'native_queries'=>$count]),"\n";
