<?php
// Load .env if present
$envPath = __DIR__ . '/../.env';
$envLocalPath = __DIR__ . '/../.env.local';

function loadEnv($path) {
    if (file_exists($path)) {
        $lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        foreach ($lines as $line) {
            if (str_starts_with(trim($line), '#')) continue;
            [$k, $v] = array_pad(explode('=', $line, 2), 2, '');
            $_ENV[trim($k)] = trim($v);
        }
    }
}

loadEnv($envPath);
loadEnv($envLocalPath);


define('DB_HOST', $_ENV['DB_HOST'] ?? 'localhost');
define('DB_NAME', $_ENV['DB_NAME'] ?? 'grocery');
define('DB_USER', $_ENV['DB_USER'] ?? 'root');
define('DB_PASS', $_ENV['DB_PASS'] ?? '');
define('APP_SECRET', $_ENV['APP_SECRET'] ?? 'change-me');

// GST default
define('DEFAULT_GST_RATE', 5.0);
define('BASE_URL', '/grocery_billing');