<?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'),'V47','47.0.0','ERROR',500,'',false);
require_once dirname(__DIR__).'/decision/ChairmanPreRaceDecisionEngineV47.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']):''; $raceNum=isset($_GET['race_num'])?intval($_GET['race_num']):0;
$mode=isset($_GET['mode'])?strtoupper(trim($_GET['mode'])):'BALANCED'; $action=isset($_GET['action'])?$_GET['action']:'latest';
$engine=new ChairmanPreRaceDecisionEngineV47($conn); $result=$action==='build'?$engine->build($date,$venue,$raceNum,$mode):$engine->latest($date,$venue,$raceNum);
wr_json_response($result,'V47','47.0.0',empty($result)?'EMPTY':'OK',200,$date.'|'.$venue.'|R'.$raceNum,!empty($result));
