<?php
// Enable full error reporting
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

echo "<h1>Debug Start</h1>";

// 1. Check PHP Version
echo "<h2>1. PHP Version</h2>";
echo "PHP Version: " . phpversion() . "<br>";

// 2. Check File Existence
echo "<h2>2. Critical Files Check</h2>";
$files = [
    'config/settings.php',
    'config/database.php',
    'vendor/autoload.php',
    'helpers/Response.php',
    'config/firebase_credentials.json'
];

foreach ($files as $file) {
    echo "File '$file': " . (file_exists(__DIR__ . '/' . $file) ? "<span style='color:green'>Found</span>" : "<span style='color:red'>MISSING</span>") . "<br>";
}

// 3. Test Database Connection
echo "<h2>3. Database Connection</h2>";
try {
    if (file_exists(__DIR__ . '/config/database.php')) {
        require_once __DIR__ . '/config/database.php';
        $database = new Database();
        $db = $database->getConnection();
        echo "<span style='color:green'>Database Connection Successful!</span><br>";
    } else {
        echo "<span style='color:red'>Skipping DB test (config missing)</span><br>";
    }
} catch (Throwable $e) {
    echo "<span style='color:red'>Database Error: " . $e->getMessage() . "</span><br>";
}

// 4. Test Vendor/Firebase
echo "<h2>4. Vendor & Firebase Check</h2>";
try {
    if (file_exists(__DIR__ . '/vendor/autoload.php')) {
        require_once __DIR__ . '/vendor/autoload.php';
        echo "Vendor autoload included.<br>";

        if (class_exists('Kreait\Firebase\Factory')) {
            echo "<span style='color:green'>Kreait\Firebase\Factory class FOUND.</span><br>";
        } else {
            echo "<span style='color:red'>Kreait\Firebase\Factory class NOT FOUND. Check 'composer install'.</span><br>";
        }
    } else {
        echo "<span style='color:red'>Vendor autoload missing. Dependencies not installed.</span><br>";
    }
} catch (Throwable $e) {
    echo "<span style='color:red'>Vendor/Firebase Error: " . $e->getMessage() . "</span><br>";
}

echo "<h1>Debug End</h1>";
