<?php
/**
 * Initialization File
 */

// Load environment variables
if (file_exists(__DIR__ . '/../.env')) {
    $dotenv = parse_ini_file(__DIR__ . '/../.env');
    foreach ($dotenv as $key => $value) {
        putenv("$key=$value");
        $_ENV[$key] = $value;
    }
}

// Define constants
require_once __DIR__ . '/constants.php';

// Set error reporting
if (Config::get('app_env') === 'production') {
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
} else {
    error_reporting(0);
    ini_set('display_errors', 0);
}

// Set timezone
date_default_timezone_set(Config::get('timezone', 'Africa/Lagos'));

// Start session
require_once __DIR__ . '/../core/Session.php';
Session::init();

// Load core classes
require_once __DIR__ . '/../core/Database.php';
require_once __DIR__ . '/../core/Auth.php';
require_once __DIR__ . '/../core/Security.php';
require_once __DIR__ . '/../core/AuditLogger.php';
require_once __DIR__ . '/../core/Uploader.php';
require_once __DIR__ . '/../core/Validator.php';

// Set base URL
define('BASE_URL', Config::get('app_url', 'https://nis-migrant.com.ng/nis_ams'));
define('BASE_PATH', dirname(__DIR__));