<?php
declare(strict_types=1);date_default_timezone_set('Asia/Shanghai');require __DIR__.'/oracle.php';require __DIR__.'/cases.php';
set_exception_handler(static function(Throwable $error):void{smSave('restaurant-prepare-tool-error-private.json',['class'=>get_class($error),'message'=>$error->getMessage()]);echo json_encode(['status'=>'tool-error','class'=>get_class($error),'message_sha256'=>hash('sha256',$error->getMessage())]),PHP_EOL;exit(1);});
$db=smPdo();$sha=catSha();catActor($db);$runtime=getenv('SM7_RUNTIME');if(is_file($runtime.'/restaurant-spec-private.json')){throw new RuntimeException('Restaurant first-request guard');}
define('APP_PATH',getenv('SM7_ROOT').'/application/');require APP_PATH.'base/Security.php';$actor=smLoad('actor-private.json');$token=\app\base\Security::encrypt(implode("\t",[(string)$actor['id'],$actor['uuid'],$actor['marker'],'0','','',$actor['marker']]));$items=[];$spec=[];
foreach(n7Cases(smLoad('candidates-private.json')['candidates']) as $case){if(strpos($case['kind'],'restaurant_')!==0){continue;}$proof=n7Snapshot($db,$case);$body=[];foreach($case['params'] as $key=>$value){$body[]=['key'=>$key,'value'=>(string)$value,'type'=>'text'];}$expected=json_encode($proof['body'],JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR);
 $items[]=['id'=>'catalog7-'.$case['name'],'name'=>$case['name'],'type'=>'http','metaInfo'=>['type'=>'HTTP'],'request'=>['method'=>'POST','url'=>getenv('SM7_BASE').$case['path'],'header'=>[['key'=>'token','value'=>$token],['key'=>'Content-Type','value'=>'application/x-www-form-urlencoded'],['key'=>'X-Pilot-Scenario','value'=>'PILOT_CAT7_'.$case['name']]],'body'=>['mode'=>'urlencoded','urlencoded'=>$body]],'event'=>[['listen'=>'test','script'=>['type'=>'text/javascript','exec'=>["pm.test('HTTP 200',()=>pm.response.to.have.status(200));",'const expected='.$expected.';',"pm.test('independent full restaurant source contract',()=>pm.expect(pm.response.json()).to.deep.equal(expected));"]]]]];$spec[]=$case+['before'=>$proof];
}
if(count($spec)!==4){throw new RuntimeException('Frozen restaurant four scenarios missing');}
smSave('restaurant-spec-private.json',$spec);
$collection=['apifoxCli'=>'2.2.8','info'=>['name'=>'Frozen restaurant full-star reads after root column alignment'],'item'=>[['name'=>'Four readonly restaurant scenarios','item'=>$items]]];
smSave('restaurant-collection-private.json',$collection);
echo json_encode(['lane'=>getenv('SM7_LANE'),'prepared_cases'=>4,'business_dml_ddl'=>0]),PHP_EOL;
