<?php
/** WinRacing Runtime Foundation V50.3 - shared runtime state. PHP 7.4 compatible. */
if (!defined('WR_RUNTIME_V503')) define('WR_RUNTIME_V503', '50.3.1');
if (!defined('WR_RUNTIME_STARTED_AT')) define('WR_RUNTIME_STARTED_AT', microtime(true));
if (!defined('WR_RUNTIME_MEMORY_AT_START')) define('WR_RUNTIME_MEMORY_AT_START', memory_get_usage(true));
if (!defined('WR_RUNTIME_REQUEST_ID')) {
    try { $wrRid = bin2hex(random_bytes(8)); }
    catch (Throwable $e) { $wrRid = str_replace('.', '', uniqid('wr', true)); }
    define('WR_RUNTIME_REQUEST_ID', $wrRid);
}
if (!function_exists('wr_runtime_request_id')) { function wr_runtime_request_id(){ return WR_RUNTIME_REQUEST_ID; } }
if (!function_exists('wr_runtime_execution_ms')) { function wr_runtime_execution_ms(){ return round((microtime(true)-WR_RUNTIME_STARTED_AT)*1000, 3); } }
if (!function_exists('wr_runtime_memory_mb')) { function wr_runtime_memory_mb(){ return round(memory_get_usage(true)/1048576, 3); } }
if (!function_exists('wr_runtime_is_api')) {
    function wr_runtime_is_api(){
        if (defined('WR_RUNTIME_FORCE_API')) return (bool)WR_RUNTIME_FORCE_API;
        $script = isset($_SERVER['SCRIPT_NAME']) ? strtolower((string)$_SERVER['SCRIPT_NAME']) : '';
        $accept = isset($_SERVER['HTTP_ACCEPT']) ? strtolower((string)$_SERVER['HTTP_ACCEPT']) : '';
        return strpos($script, '/api/') !== false || strpos(basename($script), 'api_') === 0 || strpos($accept, 'application/json') !== false || isset($_GET['wr_chairman_payload']) || isset($_GET['wr_ai_decision_writer']);
    }
}
