<?php
// Al Runan Backend Configuration
// Update these settings for your cPanel deployment

// Database Configuration
define('DB_HOST', 'localhost');
define('DB_NAME', 'alrunan_db');
define('DB_USER', 'your_database_user');
define('DB_PASS', 'your_database_password');

// JWT Secret Key (Change this to a random string in production)
define('JWT_SECRET', 'alrunan-jwt-secret-key-2024-change-in-production');

// Base URL Configuration
define('BASE_URL', 'https://your-domain.com/alrunan');

// CORS Configuration
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');

// Handle preflight requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    http_response_code(200);
    exit();
}

// Database connection function
function getDB() {
    static $db = null;
    
    if ($db === null) {
        try {
            $db = 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) {
            http_response_code(500);
            echo json_encode([
                'success' => false,
                'message' => 'Database connection failed: ' . $e->getMessage()
            ]);
            exit();
        }
    }
    
    return $db;
}

// Helper function to get base URL
function getBaseUrl() {
    return BASE_URL;
}

// Helper function to get JWT secret
function getJwtSecret() {
    return JWT_SECRET;
}
?>