<?php
require_once __DIR__ . '/config.php';
$db = db();

try {
    $db->exec("CREATE TABLE IF NOT EXISTS game_resources (
        id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(255) NOT NULL,
        slug VARCHAR(255) NOT NULL UNIQUE,
        icon VARCHAR(100) DEFAULT NULL,
        image_url VARCHAR(255) DEFAULT NULL,
        description TEXT DEFAULT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");

    // Insert a default example resource as requested
    $stmt = $db->prepare("SELECT COUNT(*) FROM game_resources WHERE slug = ?");
    $stmt->execute(['credits']);
    if ($stmt->fetchColumn() == 0) {
        $db->exec("INSERT INTO game_resources (name, slug, icon, description) VALUES ('Crédits Galactiques', 'credits', 'fa-coins', 'Monnaie standard utilisée pour les transactions interstellaires.')");
    }

    echo "Migration completed: game_resources table created and example resource added.\n";
} catch (PDOException $e) {
    die("Migration failed: " . $e->getMessage() . "\n");
}

