<?php
require_once 'config.php';

checkAccess(['admin', 'programmer', 'board']);

$data = json_decode(file_get_contents("php://input"), true);

if (!$data || !isset($data['question'])) response(["error" => "Faltan datos"], 400);

try {
    $stmt = $pdo->prepare("INSERT INTO live_votes (question, options_json, status) VALUES (?, ?, ?)");
    $stmt->execute([
        $data['question'],
        json_encode($data['options']),
        'Borrador'
    ]);
    response(["success" => true]);
} catch (PDOException $e) {
    response(["error" => $e->getMessage()], 500);
}
?>