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

try {
    // Create 'streams' table
    $sql = "CREATE TABLE IF NOT EXISTS streams (
        id INT AUTO_INCREMENT PRIMARY KEY,
        user_id INT NOT NULL,
        title VARCHAR(150),
        stream_key VARCHAR(100) NOT NULL UNIQUE,
        is_live BOOLEAN DEFAULT FALSE,
        viewers INT DEFAULT 0,
        started_at DATETIME NULL,
        ended_at DATETIME NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
    )";
    $pdo->exec($sql);
    echo "✅ Table 'streams' created successfully.<br>";

    echo "<hr>🎉 Streaming DB Setup Complete!";

} catch (PDOException $e) {
    die("❌ DB Error: " . $e->getMessage());
}
?>
