<?php
// =========================================================
// RMS Config - Restaurant Management System
// Anuradhapura Rice & Curry
// =========================================================

// --- Environment: change to 'live' when deploying to cPanel ---
define('APP_ENV', 'local'); // 'local' (XAMPP) or 'live' (cPanel)

// --- Database ---
define('DB_HOST', 'localhost');
define('DB_NAME', 'rms_anuradhapura');
define('DB_USER', 'root');
define('DB_PASS', '');       // set live cPanel DB password when deploying
define('DB_CHARSET', 'utf8mb4');

// --- Base URL detection (XAMPP local vs cPanel live) ---
if (APP_ENV === 'local') {
    // Auto-detect scheme + host + port so this works whether XAMPP's Apache
    // is on port 80, 8080, or anything else — no manual port edits needed.
    $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
    $host   = $_SERVER['HTTP_HOST'] ?? 'localhost:8080'; // includes port if non-standard, e.g. localhost:8080 (falls back for CLI)
    define('BASE_URL', $scheme . '://' . $host . '/rms/public');
} else {
    // On cPanel, set your live domain here
    define('BASE_URL', 'https://yourdomain.com');
}

// --- App constants ---
define('APP_NAME', 'CurryPot.lk');
define('APP_CURRENCY_SYMBOL', 'LKR');
define('APP_TIMEZONE', 'Asia/Colombo');
date_default_timezone_set(APP_TIMEZONE);

// --- Paths ---
// ROOT_PATH is defined by the entry point (public/index.php) before this file loads.
if (!defined('ROOT_PATH')) {
    define('ROOT_PATH', dirname(__DIR__));
}
if (!defined('APP_PATH')) {
    define('APP_PATH', ROOT_PATH . '/app');
}
if (!defined('STORAGE_PATH')) {
    define('STORAGE_PATH', ROOT_PATH . '/storage');
}
if (!defined('UPLOADS_PATH')) {
    define('UPLOADS_PATH', STORAGE_PATH . '/uploads');
}

// --- Session ---
// IMPORTANT: session_name() must be set before any require_once that touches session helpers
if (session_status() === PHP_SESSION_NONE) {
    session_name('rms_session');
    session_start();
}

// --- Error display (turn off on live production once stable) ---
if (APP_ENV === 'local') {
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
} else {
    ini_set('display_errors', 0);
    error_reporting(0);
}
