<?php
/**
 * API Bootstrap
 * Handles common API requirements and error checking
 */

// Common headers for JSON APIs
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');

$config_path = __DIR__ . '/../admin/includes/config.php';

// 1. Check if config file exists
if (!file_exists($config_path)) {
    http_response_code(503);
    echo json_encode([
        'success' => false,
        'error' => 'System not installed',
        'message' => 'The configuration file is missing. Please run the installation script at /admin/install.php'
    ]);
    exit;
}

require_once $config_path;

// 2. Verify database connection
try {
    getDBConnection();
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode([
        'success' => false,
        'error' => 'Database connection failed',
        'message' => $e->getMessage()
    ]);
    exit;
}
