<?php
declare(strict_types=1);

require_once dirname(__DIR__) . '/_bootstrap.php';

golder_require_method('POST');
$ctx = golder_api_auth('desktop_sync');
$input = golder_api_input();

$sessionUuid = trim((string)($input['session_uuid'] ?? ''));
if ($sessionUuid === '') {
    golder_json_response(['status' => 'error', 'message' => 'session_uuid is required'], 400);
}

$st = $ctx['master']->prepare('SELECT customer_id FROM customer_web_sessions WHERE session_uuid = :sid LIMIT 1');
$st->execute([':sid' => $sessionUuid]);
$row = $st->fetch();
if (!$row || (int)($row['customer_id'] ?? 0) !== (int)$ctx['customer_id']) {
    golder_json_response(['status' => 'error', 'message' => 'Session not found'], 404);
}

golder_close_web_session($ctx['master'], $sessionUuid, 'manual_logout');

golder_json_response(['status' => 'ok']);


