<?php
declare(strict_types=1);$sent=false;$label='DIRECT_002';
try{require __DIR__.'/app.php';require __DIR__.'/observer.php';$case=json_decode(file_get_contents($runtime.'/case.json'),true);$tokens=json_decode(file_get_contents($runtime.'/tokens.json'),true);
 ck($_SERVER['REQUEST_METHOD']==='POST'&&parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH)==='/api/mealCheckout/directPay'&&($_SERVER['QUERY_STRING']??'')===''&&($_SERVER['HTTP_HOST']??'')==='core.scan-pay.invalid'&&($_SERVER['HTTP_PLATFORM']??'')==='POC'&&($_SERVER['CONTENT_TYPE']??'')==='application/json'&&($_SERVER['HTTP_X_CORE_CASE']??'')===$label&&file_get_contents('php://input')===$case['body_raw']&&($_SERVER['HTTP_ACCESS_TOKEN']??'')===$tokens['U1'],'Exact authorized HTTP bytes');
 ck(!file_exists($runtime.'/wire-attempt.json'),'Never replay once-only case');saveOnce('wire-attempt.json',['case'=>$label,'at'=>microtime(true)]);$_SERVER['SCRIPT_FILENAME']=$root.'/public/index.php';$_SERVER['SCRIPT_NAME']='/index.php';$_SERVER['PHP_SELF']='/index.php';$app=coreApp($label);
 $before=ownSnapshot();$oldBefore=oldProtection();$guard=json_decode(file_get_contents($runtime.'/guard.json'),true);ck($before===$guard['own_fullrows']&&$oldBefore===$guard['old_protection'],'All old0.01/prepay/original13 fullrow leases before HTTP');CoreGate::$lease=$before;
 $preSQL=count(file($runtime.'/independent-native.jsonl',FILE_IGNORE_NEW_LINES));$preSQL+=$guard['business_native_SQL'];ck($preSQL<=160,'Exact total preflight readonly SQL budget');saveOnce('preflight-budget.json',['independent_SELECT'=>count(file($runtime.'/independent-native.jsonl',FILE_IGNORE_NEW_LINES)),'original_guard_native'=>$guard['business_native_SQL'],'total'=>$preSQL,'cap'=>160]);
 $businessStart=microtime(true);$http=$app->http;$response=$http->run();$businessEnd=microtime(true);
 preserveSendObserve($response,function($record){$record['case']='DIRECT_002';saveOnce('response-original.json',$record);saveOnce('included-before-send.json',includedProof());},function()use($response,&$sent){$response->send();$sent=true;},function($record)use($app,$before,$oldBefore,$businessStart,$businessEnd){$lock=actualRepeatLock($app);$after=ownSnapshot();$oldAfter=oldProtection();ck($oldBefore===$oldAfter,'Original13 protected fullrows after HTTP');saveOnce('wire.json',['lane'=>getenv('CORE_LANE'),'case'=>json_decode(file_get_contents(__DIR__.'/private/case.json'),true),'response'=>$record,'own_before'=>$before,'own_after'=>$after,'original_before'=>$oldBefore,'original_after'=>$oldAfter,'native_DML_counts'=>CoreGate::$counts,'business_native_SQL'=>CoreGate::$total,'native_generated_IDs'=>CoreGate::$generated,'orderNo'=>CoreGate::$orderNo,'repeat_cache'=>$lock,'included_source_sha256'=>includedProof()]);},function($error){saveOnce('observer-error.json',$error);},$businessStart,$businessEnd);
 try{$http->end($response);}catch(Throwable $e){saveOnce('http-end-error.json',['class'=>get_class($e),'message'=>$e->getMessage(),'response_already_sent'=>true]);}
}catch(Throwable $e){if(function_exists('saveOnce')&&!file_exists($runtime.'/harness-error.json'))saveOnce('harness-error.json',['class'=>get_class($e),'message'=>$e->getMessage(),'file'=>$e->getFile(),'line'=>$e->getLine(),'sent'=>$sent]);if(!$sent){http_response_code(500);header('Content-Type: application/json');echo json_encode(['harness_error'=>get_class($e),'message'=>$e->getMessage()]);}}
