<?php
require_once __DIR__ . '/../config/bootstrap.php';
admin_require_login();
require_method('POST');

$pdo = db();
$data = get_json_body();

$id = (int)($data['id'] ?? 0);
$config = $data['config'] ?? null;

if ($id <= 0 || !is_array($config)) {
  json_response(['ok'=>false,'error'=>'Payload inválido.'], 422);
}

$cfg_json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$st = $pdo->prepare('UPDATE eventos SET config_json=?, updated_at=NOW() WHERE id=?');
$st->execute([$cfg_json, $id]);
json_response(['ok'=>true]);
