<?php
// Start session (needed for login/logout/cart later)
session_start();

// ==================== DATABASE ====================
define('DB_HOST', 'localhost');
define('DB_USER', 'reckons1_vcaa');
define('DB_PASS', 'reckons1_vca');  // ← your real password
define('DB_NAME', 'reckons1_vca');

try {
    $pdo = new PDO(
        "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4",
        DB_USER,
        DB_PASS,
        [
            PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES   => false,
        ]
    );
} catch (PDOException $e) {
    // Hide real error in production, show simple message
    die("Database connection failed. Check your config.php");
}

// ==================== STRIPE KEYS ====================
define('STRIPE_PUB', 'pk_test_51XXXXXXXXXXXXXXXXXXXXXXXX'); // ← PUT YOUR REAL ONE HERE
define('STRIPE_SEC', 'sk_test_51XXXXXXXXXXXXXXXXXXXXXXXX'); // ← PUT YOUR REAL ONE HERE

// ==================== SERVER INFO ====================
define('SERVER_IP',   'play.reckonsoul.fun');
define('SERVER_NAME', 'Reckon');
define('SERVER_URL',  'https://reckonsoul.fun/oksi');           // Main website
define('STORE_URL',   'https://store.reckonsoul.fun');     // This store

// ==================== ADMIN AUTO-CREATE ====================
define('ADMIN_USERNAME',      'admin');
define('ADMIN_DEFAULT_PASS',  'reckon123'); // Change this later in admin panel!

if (!isset($_SESSION['admin_checked'])) {
    try {
        $count = $pdo->query("SELECT COUNT(*) FROM admins")->fetchColumn();
        if ($count == 0) {
            $hash = password_hash(ADMIN_DEFAULT_PASS, PASSWORD_BCRYPT);
            $pdo->prepare("INSERT INTO admins (username, password) VALUES (?, ?)")->execute([
                ADMIN_USERNAME, $hash
            ]);
        }
    } catch (Exception $e) {
        // Silent if table doesn't exist yet (first install)
    }
    $_SESSION['admin_checked'] = true;
}

// ==================== HELPER FUNCTIONS ====================
function hashPass($pass) {
    return password_hash($pass, PASSWORD_BCRYPT);
}

function verifyPass($pass, $hash) {
    return password_verify($pass, $hash);
}

// Optional: Prevent direct access
// if (basename($_SERVER['PHP_SELF']) == 'config.php') {
//     die('Direct access not allowed');
// }
?>