<?php
require_once __DIR__.'/db.php';
$templateUUID=$lane==='B'?'3F0D313A-CF55-4160-B343-ED9D059D51A4':'4F2D4622-8311-45D6-88DB-2C7710D984BF';$stationUUID=$lane==='B'?'8FB65B8D-E006-63CC-C111-2744E7166799':'A2B10878-C280-4419-AC02-FF5425D41E94';$productUUID=$lane==='B'?'6969DC3F-CC71-237D-FCED-389B86C5905F':'711DB31A-5BF6-4478-BB9E-C866F0C88DA3';
$source=static function()use($q,$p,$templateUUID,$stationUUID,$productUUID):array {
 $data=[];foreach(['nutrition_template','nutrition_template_ext','nutrition_station','nutrition_station_ext','nutrition_set','nutrition_time'] as $table)$data[$table]=$q('SELECT * FROM '.$p.$table.' ORDER BY ID');
 $data['annex']=$q('SELECT * FROM '.$p.'annex WHERE MASTER_UUID=?',[$stationUUID]);$data['annex_path_native_order']=$q('SELECT FILE_PATH FROM '.$p.'annex WHERE MASTER_UUID=?',[$stationUUID]);
 $data['product']=$q('SELECT * FROM '.$p.'nutrition WHERE UUID=?',[$productUUID]);if(count($data['product'])!==1)throw new RuntimeException('Same local product');
 $links=array_values(array_filter($data['nutrition_station_ext'],static function($r)use($stationUUID){return $r['station_uuid']===$stationUUID;}));$uuids=array_values(array_unique(array_filter(array_column($links,'nutrition_uuid'))));$data['station_link_products']=$uuids?$q('SELECT * FROM '.$p.'nutrition WHERE UUID IN ('.implode(',',array_fill(0,count($uuids),'?')).') ORDER BY ID',$uuids):[];
 $data['station_ext_native_order']=$q('SELECT * FROM '.$p.'nutrition_station_ext WHERE STATION_UUID=?',[$stationUUID]);
 $data['time_cn_native_order']=$q('SELECT UUID,NAME FROM '.$p.'nutrition_time WHERE DEL_FLAG=0');
 $data['set_active_native_order']=$q('SELECT ID,UUID,NAME,ORDER_NO FROM '.$p.'nutrition_set WHERE IS_DEL=1 AND STATUS=1 ORDER BY ORDER_NO ASC,ID DESC');$data['set_reference_count']=[];
 foreach($data['set_active_native_order'] as $set)$data['set_reference_count'][$set['uuid']]=(int)$q('SELECT COUNT(*) AS CNT FROM '.$p.'nutrition WHERE IS_DEL=1 AND STATUS=1 AND SET_UUID=?',[$set['uuid']])[0]['cnt'];
 $data['sport_roots_native_order']=$q('SELECT UUID,PUUID,NAME FROM '.$p.'sport WHERE PUUID=?',['0']);
 $actor=$q('SELECT * FROM '.$p.'user WHERE ID=1');if(count($actor)!==1||(int)$actor[0]['type']!==0||(int)$actor[0]['is_delete']!==0)throw new RuntimeException('Normal actor');$data['actor_sha256']=hash('sha256',json_encode($actor,JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION));
 return $data;
};
$guard=static function($current){$base=json_decode(file_get_contents(__DIR__.'/private-http-baseline.json'),true);if($current!==$base)throw new RuntimeException('Full source drift');};
