<?php

declare(strict_types=1);
header('Content-Type: application/json; charset=utf-8');

require_once __DIR__ . '/../../engine/engine.php';
$pdo = null;
if (isset($GLOBALS['pdo']) && $GLOBALS['pdo'] instanceof PDO) {
	$pdo = $GLOBALS['pdo'];
} elseif (function_exists('db')) {
	$pdo = db();
}
if (!$pdo instanceof PDO) {
	http_response_code(500);
	echo json_encode(['success' => false, 'message' => 'DB connection not available']);
	exit;
}

$id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
if ($id <= 0) {
	http_response_code(400);
	echo json_encode(['success' => false, 'message' => 'Ungültige ID']);
	exit;
}

$stmt = $pdo->prepare('DELETE FROM scan_results WHERE id = ? LIMIT 1');
$stmt->execute([$id]);

if ($stmt->rowCount() === 1) {
	echo json_encode(['success' => true]);
} else {
	echo json_encode(['success' => false, 'message' => 'Eintrag nicht gefunden']);
}