<?php
require __DIR__.'/db.php';
$actor=json_decode(file_get_contents(__DIR__.'/private-actor.json'),true);
$actorNow=static function()use($q,$p,$actor){return $q('SELECT ID,UUID,STAFF_UUID,ACCOUNT,TYPE,IS_DELETE FROM '.$p.'user WHERE ID=?',[$actor['id']])[0];};
$scope=json_decode(file_get_contents(__DIR__.'/private-scope.json'),true);
$source=static function()use($q,$p,$scope,$check):array{
 $rows=$q('SELECT ID,STORE_ID,EVENT_CODE,EVENT_NAME,MODULE,ACTION,RESULT,OPERATOR,USER_UUID,TARGET_TYPE,TARGET_ID,MESSAGE,TERMINAL_IP,REQUEST_METHOD,REQUEST_PATH,TRACE_ID,CONTEXT_JSON,CREATE_TIME AS CREATED_AT FROM '.$p.'security_audit_log WHERE STORE_ID=10001 AND IS_DELETE=0 AND EVENT_CODE=? AND CREATE_TIME>=? AND CREATE_TIME<=? ORDER BY ID DESC',[$scope['event_code'],$scope['date'].' 00:00:00',$scope['date'].' 23:59:59']);
 $check(count($rows)<=100,'Source cap100');foreach($rows as $r)$check(strlen((string)$r['context_json'])<=262144,'Context cap256KiB');return $rows;
};
