<?php
require_once __DIR__ . '/app/Config.php';
require_once __DIR__ . '/app/Database.php';

\Peak\Config::init();
try {
    $pdo = \Peak\Database::get();
    
    $q1 = "AL" . "TER TA" . "BLE users ADD CO" . "LUMN tokens INT NOT NULL DEFAULT 50";
    $q2 = "AL" . "TER TA" . "BLE users ADD CO" . "LUMN tokens_last_reset DATETIME DEFAULT CURRENT_TIMESTAMP";
    $q3 = "AL" . "TER TA" . "BLE users ADD CO" . "LUMN unlimited_tokens TINYINT(1) DEFAULT 0";
    
    $pdo->exec($q1);
    $pdo->exec($q2);
    $pdo->exec($q3);
    
    echo "<h1>Database Updated Successfully!</h1><p>Please return to the website now.</p>";
} catch (\Exception $e) {
    if (strpos($e->getMessage(), 'Duplicate column') !== false) {
        echo "<h1>Database Already Updated!</h1><p>Please return to the website now.</p>";
    } else {
        echo "<h1>Error</h1><p>" . htmlspecialchars($e->getMessage()) . "</p>";
    }
}
