<?php
// Application Environment
if (!defined('ENVIRONMENT')) {
    define('ENVIRONMENT', 'production'); // Set to 'production' for live website
}

// Set to true temporarily to see detailed login/register errors on screen.
// Set back to false before going live.
if (!defined('SHOW_DEBUG_ERRORS')) {
    define('SHOW_DEBUG_ERRORS', false);
}

// Database Configuration
if (!defined('DB_HOST')) {
    define('DB_HOST', 'localhost');
}
if (!defined('DB_NAME')) {
    define('DB_NAME', 'dcfinanc_avondex');
}
if (!defined('DB_USER')) {
    define('DB_USER', 'dcfinanc_adslord');
}
if (!defined('DB_PASS')) {
    define('DB_PASS', 'guardian123');
}

// Site Configuration
if (!defined('SITE_URL')) {
    define('SITE_URL', 'https://invest@avondcapital.org');
}
if (!defined('SITE_NAME')) {
    define('SITE_NAME', 'Avondex Capital'); // Change this to your domain/brand name
}
if (!defined('SITE_EMAIL')) {
    define('SITE_EMAIL', 'invest@avondcapital.org');
}
if (!defined('ADMIN_EMAIL')) {
    define('ADMIN_EMAIL', 'invest@dcfinancialcorporation.com');
}

// Email Configuration (for PHPMailer)
if (!defined('SMTP_HOST')) {
    define('SMTP_HOST', 'mail.avondeapital.org'); // e.g., smtp.gmail.com
}
if (!defined('SMTP_PORT')) {
    define('SMTP_PORT', 465); // 587 for TLS, 465 for SSL
}
if (!defined('SMTP_USERNAME')) {
    define('SMTP_USERNAME', 'invest@avondcapital.org');
}
if (!defined('SMTP_PASSWORD')) {
    define('SMTP_PASSWORD', 'Light@2026');
}
if (!defined('SMTP_ENCRYPTION')) {
    define('SMTP_ENCRYPTION', 'ssl'); // 'tls' or 'ssl'
}

// Security Keys (Generate unique ones)
if (!defined('SECRET_KEY')) {
    define('SECRET_KEY', bin2hex(random_bytes(32)));
}
if (!defined('ENCRYPTION_KEY')) {
    define('ENCRYPTION_KEY', bin2hex(random_bytes(16)));
}

// Session Configuration
if (session_status() == PHP_SESSION_NONE && !headers_sent()) {
    $isHttps = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
        || (isset($_SERVER['SERVER_PORT']) && (int) $_SERVER['SERVER_PORT'] === 443)
        || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https');

    ini_set('session.cookie_httponly', 1);
    ini_set('session.cookie_secure', $isHttps ? '1' : '0');
    ini_set('session.use_strict_mode', 1);
    ini_set('session.cookie_samesite', 'Lax');
}

// Error Reporting
$showErrors = (ENVIRONMENT === 'development' || SHOW_DEBUG_ERRORS);
if ($showErrors) {
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
} else {
    error_reporting(E_ALL);
    ini_set('display_errors', '0');
}
ini_set('log_errors', '1');
ini_set('error_log', __DIR__ . '/../error_log');

// Timezone
date_default_timezone_set('UTC');

// Composer Autoload (if using packages)
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}
?>