<?php
declare(strict_types=1);

require_once __DIR__ . '/includes/bootstrap.php';

echo "Testing Settings System\n";
echo "=======================\n\n";

try {
    // Test if Settings class exists
    if (!class_exists('Settings')) {
        echo "✗ Settings class not found!\n";
        exit(1);
    }
    echo "✓ Settings class loaded\n";
    
    // Test database connection
    $pdo = Database::pdo();
    echo "✓ Database connected\n";
    
    // Test if settings table exists
    $stmt = $pdo->query("SHOW TABLES LIKE 'settings'");
    if ($stmt->rowCount() === 0) {
        echo "✗ Settings table does not exist!\n";
        exit(1);
    }
    echo "✓ Settings table exists\n";
    
    // Test loading settings
    Settings::load();
    echo "✓ Settings loaded\n";
    
    // Test getting a setting
    $appName = Settings::get('app_name', 'DEFAULT');
    echo "✓ App Name: " . $appName . "\n";
    
    // Show all settings
    echo "\nAll Settings:\n";
    $all = Settings::all();
    foreach ($all as $key => $value) {
        echo "  - $key = $value\n";
    }
    
    echo "\n✓ Settings system working correctly!\n";
    
} catch (Throwable $e) {
    echo "✗ Error: " . $e->getMessage() . "\n";
    echo "  File: " . $e->getFile() . "\n";
    echo "  Line: " . $e->getLine() . "\n";
    exit(1);
}
