<?php
require_once '../../config/cors.php';
require_once '../../config/db.php';
require_once '../../helpers/response.php';

$headers = getallheaders();
$token = str_replace('Bearer ', '', $headers['Authorization'] ?? '');

// Admin check (simplified)
$data = json_decode(file_get_contents('php://input'), true);
$stream_id = $data['stream_id'] ?? null;
$enabled = $data['enabled'] ?? true;

if (!$stream_id) {
    sendError('Stream ID required', 400);
}

$stmt = $pdo->prepare("UPDATE live_streams SET chat_enabled = ? WHERE id = ?");
$stmt->execute([$enabled ? 1 : 0, $stream_id]);

sendSuccess(null, $enabled ? 'Chat enabled' : 'Chat disabled');
?>