<?php
define('ROOT',     dirname(__DIR__));
define('APP',      ROOT . '/app');
define('VIEWS',    ROOT . '/views');
define('CONFIG',   ROOT . '/config');
define('STORAGE',  ROOT . '/storage');
define('BASE_URL', 'http://' . ($_SERVER['HTTP_HOST'] ?? 'localhost') . '/cbe/sms/public');

// ── Security Headers ──────────────────────────────────────
header('X-Frame-Options: SAMEORIGIN');
header('X-Content-Type-Options: nosniff');
header('X-XSS-Protection: 1; mode=block');
header('Referrer-Policy: strict-origin-when-cross-origin');
header('Permissions-Policy: camera=(), microphone=(), geolocation=()');

// ── Error Reporting (set to 0 in production) ──────────────
error_reporting(E_ALL);
ini_set('display_errors', 0);  // Never show errors to browser in production
ini_set('log_errors', 1);

spl_autoload_register(function (string $class) {
    $map = [
        'Core\\'        => APP . '/Core/',
        'Controllers\\' => APP . '/Controllers/',
        'Models\\'      => APP . '/Models/',
        'Services\\'    => APP . '/Services/',
        'Middleware\\'  => APP . '/Middleware/',
    ];
    foreach ($map as $prefix => $dir) {
        if (str_starts_with($class, $prefix)) {
            $file = $dir . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php';
            if (file_exists($file)) { require_once $file; return; }
        }
    }
    // Fallback: all extra models live in Models/Models.php
    if (str_starts_with($class, 'Models\\')) {
        $bundle = APP . '/Models/Models.php';
        if (file_exists($bundle)) { require_once $bundle; return; }
    }
});

require_once APP . '/Core/App.php';
(new Core\App())->run();
