<?php
declare(strict_types=1);

require_once __DIR__ . '/../../includes/bootstrap.php';
require_once __DIR__ . '/../../includes/CaseStore.php';

dbnToolsRequireMethod('POST');
dbnToolsRequireAuth();

$userId = (int)($_SESSION['dbn_tools_sso_uid'] ?? 0);
if ($userId <= 0) {
    dbnToolsError('Auth required.', 401, 'auth_required');
}

$input = dbnToolsJsonInput(500);
$docId = (int)($input['doc_id'] ?? 0);
if ($docId <= 0) {
    dbnToolsError('doc_id required.', 400, 'bad_input');
}

$ok = CaseStore::deleteDocument($userId, $docId);
if (!$ok) {
    dbnToolsError('Dokumentet finnes ikke, eller er allerede slettet.', 404, 'not_found');
}

dbnToolsRespond(['ok' => true, 'doc_id' => $docId]);
