<?php
require_once __DIR__ . '/../config/cors.php';
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../helpers/auth.php';
require_once __DIR__ . '/cloudflare.php';

$admin = requireAdmin();
$data = json_decode(file_get_contents('php://input'), true);

$id = $data['id'] ?? null;
$enabled = $data['enabled'] ?? true;

if (!$id) sendError('ID required', 400);

$stmt = $pdo->prepare("SELECT cloudflare_input_id FROM live_inputs WHERE id = ?");
$stmt->execute([$id]);
$input = $stmt->fetch();
if (!$input) sendError('Not found', 404);

$result = cf_update_live_input($input['cloudflare_input_id'], $enabled);
sendSuccess(null, $enabled ? 'Stream enabled' : 'Stream disabled');
?>