<?php
require_once '../../engine/engine.php';

$symbol = $_POST['symbol'] ?? '';
$criteria = json_decode($_POST['checked'] ?? '[]');
$note = $_POST['note'] ?? '';

if (!$symbol || !is_array($criteria)) {
	http_response_code(400);
	exit('Ungültige Daten');
}

$json = json_encode($criteria);

// Aktualisiere sowohl rating_criteria als auch note
$stmt = $pdo->prepare("UPDATE watchlist SET rating_criteria = ?, note = ? WHERE symbol = ? ORDER BY id DESC LIMIT 1");
$stmt->execute([$json, $note, $symbol]);

echo 'OK';
