<?php
/**
 * Configuration wrapper
 * Reads values from .env via TonEnv loader. No secrets are hardcoded here.
 */

require_once __DIR__ . '/includes/Env.php';
TonEnv::load();

// Base config from env
$config = [
    // Database Configuration
    'db_host' => TonEnv::get('DB_HOST', 'localhost'),
    'db_name' => TonEnv::get('DB_NAME', 'tonsui_test'),
    'db_user' => TonEnv::get('DB_USER', 'root'),
    'db_pass' => TonEnv::get('DB_PASS', ''),
    'db_port' => TonEnv::get('DB_PORT', '3306'),

    // SMTP Configuration
    'smtp_host' => TonEnv::get('SMTP_HOST', 'smtp.example.com'),
    'smtp_port' => TonEnv::get('SMTP_PORT', 587),
    'smtp_user' => TonEnv::get('SMTP_USER', 'noreply@example.com'),
    'smtp_pass' => TonEnv::get('SMTP_PASS', ''),
    'smtp_from' => TonEnv::get('SMTP_FROM', 'noreply@example.com'),
    'smtp_from_name' => TonEnv::get('SMTP_FROM_NAME', 'First De France'),
    'smtp_secure' => TonEnv::get('SMTP_SECURE', 'tls'),

    // Contact Form
    'contact_email' => TonEnv::get('CONTACT_EMAIL', 'info@firstdefrance.com'),

    // App
    'app_url' => TonEnv::get('APP_URL', ''),
    'kyc_required' => (string) TonEnv::get('KYC_REQUIRED', '1') === '1',
];

// Optional: local/server overrides for non-secret toggles (do not override DB/SMTP/app_url)
$protectedKeys = [
    'db_host','db_name','db_user','db_pass','db_port',
    'smtp_host','smtp_port','smtp_user','smtp_pass','smtp_from','smtp_from_name','smtp_secure',
    'app_url'
];
foreach (['config.local.php', 'config.server.php'] as $file) {
    $path = __DIR__ . '/' . $file;
    if (is_file($path)) {
        $override = require $path;
        if (is_array($override)) {
            foreach ($override as $k => $v) {
                if (!in_array($k, $protectedKeys, true)) {
                    $config[$k] = $v;
                }
            }
        }
    }
}

return $config;
