<?php
defined('CHAIRMAN_ROOT') || define('CHAIRMAN_ROOT', dirname(__DIR__));

$configCandidates = array(
    __DIR__ . '/config.php',
    dirname(CHAIRMAN_ROOT) . '/config/config.php',
    dirname(dirname(CHAIRMAN_ROOT)) . '/config/config.php'
);

$loadedConfig = '';
foreach ($configCandidates as $cfg) {
    if (file_exists($cfg)) {
        $loadedConfig = $cfg;
        require_once $cfg;
        break;
    }
}
if ($loadedConfig === '') {
    die('Chairman DB config not found. Tried: ' . htmlspecialchars(implode(' | ', $configCandidates), ENT_QUOTES, 'UTF-8'));
}
if (!isset($conn) && isset($db)) { $conn = $db; }
if (!isset($conn) || !($conn instanceof mysqli)) {
    die('DB connection not found. Need $conn or $db in config.php.');
}
$conn->set_charset('utf8mb4');

return array(
    'framework_version' => '2.0',
    'root' => CHAIRMAN_ROOT,
    'loaded_config' => $loadedConfig,
    'cache_dir' => CHAIRMAN_ROOT . '/cache',
    'log_dir' => CHAIRMAN_ROOT . '/logs',
    'hide_absolute_path' => false
);
