<?php
/**
 * GeoGraSim — App Configuration
 * Umgebungserkennung und Grundkonstanten
 */

// Umgebungserkennung via Hostname
define('IS_PRODUCTION', isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] !== 'localhost');
define('BASE_PATH', '/geograsim/App');
define('BASE_URL', (IS_PRODUCTION ? 'https://www.staatsgeheimnis.at' : 'http://localhost') . BASE_PATH);
define('APP_ROOT', dirname(__DIR__, 2));

// .env laden
$envFile = IS_PRODUCTION
    ? APP_ROOT . '/.env.production'
    : APP_ROOT . '/.env.local';

if (file_exists($envFile)) {
    $lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    foreach ($lines as $line) {
        $line = trim($line);
        if ($line === '' || $line[0] === '#') continue;
        if (strpos($line, '=') === false) continue;
        [$key, $value] = explode('=', $line, 2);
        $key = trim($key);
        $value = trim($value);
        if (!defined($key)) {
            define($key, $value);
        }
    }
}

// Defaults fuer lokale Entwicklung (XAMPP)
if (!defined('DB_HOST'))  define('DB_HOST', 'localhost');
if (!defined('DB_NAME'))  define('DB_NAME', 'geograsim');
if (!defined('DB_USER'))  define('DB_USER', 'root');
if (!defined('DB_PASS'))  define('DB_PASS', '');
if (!defined('DB_PORT'))  define('DB_PORT', '3306');
