<?php
require_once dirname(__DIR__,2).'/runtime/wr_bootstrap.php';
@set_time_limit(1200); @ini_set('memory_limit','1536M');
require_once dirname(__DIR__,2).'/config/config.php';
if(!wr_db_guard_normalize()) wr_json_response(array('message'=>'DB connection unavailable'),'V50','50.0.0','ERROR',500,'',false);
require_once dirname(__DIR__).'/ultimate/ChairmanUltimateDecisionEngineV50.php';
$date=isset($_GET['race_date'])?trim($_GET['race_date']):(isset($_GET['date'])?trim($_GET['date']):(isset($_GET['review_date'])?trim($_GET['review_date']):date('Y-m-d')));
$venue=isset($_GET['venue'])?trim($_GET['venue']):''; $action=isset($_GET['action'])?$_GET['action']:'latest';
$engine=new ChairmanUltimateDecisionEngineV50($conn); $result=$action==='build'?$engine->build($date,$venue):$engine->latest($date,$venue);
wr_json_response($result,'V50','50.0.0',empty($result)?'EMPTY':'OK',200,$date.'|'.$venue,!empty($result));
