<?php
require '/config/db.php';

try {
    // 1. Create wishlist table if not exists
    $pdo->exec("CREATE TABLE IF NOT EXISTS wishlist (
        id INT AUTO_INCREMENT PRIMARY KEY,
        user_id INT NOT NULL,
        product_id INT NOT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
        FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE,
        UNIQUE KEY user_product (user_id, product_id)
    )");
    echo "Table 'wishlist' confirmed/created successfully.\n";

    // 2. Check and insert 'Teen' category
    $stmt = $pdo->prepare("SELECT id FROM categories WHERE slug = ?");
    $stmt->execute(['teen']);
    $teen = $stmt->fetch();

    if (!$teen) {
        $stmt_insert = $pdo->prepare("INSERT INTO categories (name, image, slug) VALUES (?, ?, ?)");
        $stmt_insert->execute(['Teen', 'cat_teen.png', 'teen']);
        echo "Category 'Teen' added successfully.\n";
    } else {
        echo "Category 'Teen' already exists.\n";
    }

} catch (Exception $e) {
    echo "Database upgrade failed: " . $e->getMessage() . "\n";
}
?>
