<?php
require_once __DIR__ . '/../../config.php';
require_once __DIR__ . '/../../engine/Kernel.php';
require_once __DIR__ . '/../../engine/Logger.php';
$ctx = Kernel::handle(['auth' => 'optional']);
$u = $ctx['user'];
if (!$u) { http_response_code(401); exit; }
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); exit; }
$b   = json_decode(file_get_contents('php://input'), true) ?? [];
$res = in_array($b['response']??'', ['positive','negative','ignored']) ? $b['response'] : 'ignored';
try {
    require_once __DIR__ . '/../../engine/ScoringAgent.php';
    ScoringAgent::recordResponse((int)$u['id'], $res);
    echo json_encode(['ok'=>true]);
} catch (Throwable $e) {
    echo json_encode(['ok'=>false]);
}
