<?php
/**
 * NEXUS Commerce - Global Configuration (config.php)
 */

// 1. Timezone & General Settings
date_default_timezone_set('Asia/Bangkok');
error_reporting(E_ALL);
ini_set('display_errors', 1);

// 2. Start Session if not already started
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// --------------------------------------------------
// Environment Switcher (true = Host จริง / Production, false = Localhost / XAMPP)
// --------------------------------------------------
$is_production = true;

if ($is_production) {
    // --------------------------------------------------
    // [ตั้งค่าฐานข้อมูล HOST จริง / PRODUCTION]
    // --------------------------------------------------
    define('DB_HOST', 'localhost');         // หรือ IP / Hostname ที่โฮสติ้งกำหนด เช่น mysql.host.com
    define('DB_NAME', 'shop69319090040');   // ชื่อฐานข้อมูลบนโฮสต์ (DB_NAME)
    define('DB_USER', 'u69319090040');      // ชื่อผู้ใช้ฐานข้อมูลบนโฮสต์ (DB_USER)
    define('DB_PASS', '@6940');             // รหัสผ่านฐานข้อมูลบนโฮสต์ (DB_PASS)
} else {
    // --------------------------------------------------
    // [ตั้งค่าฐานข้อมูล LOCAL / DEVELOPMENT (XAMPP)]
    // --------------------------------------------------
    define('DB_HOST', 'localhost');
    define('DB_NAME', 'nexus_commerce');
    define('DB_USER', 'root');
    define('DB_PASS', '');
}

define('DB_CHARSET', 'utf8mb4');

// 4. SQLite Fallback Configuration
define('SQLITE_PATH', __DIR__ . '/api/nexus_database.sqlite');

// 5. Site & Application Settings
define('SITE_NAME', 'NEXUS Commerce');
define('SITE_URL', 'http://localhost/Shop40/');
define('APP_ENV', $is_production ? 'production' : 'development');

/**
 * Helper function to safely sanitize HTML input
 */
function sanitize($data) {
    return htmlspecialchars(trim($data ?? ''), ENT_QUOTES, 'UTF-8');
}
