<?php
declare(strict_types=1);

require_once __DIR__ . '/../includes/LegalTools.php';

dbnToolsRequireMethod('POST');
dbnToolsRequireAuth();
$ftUid = dbnToolsFreeTierCheck('ask');
$ftRemaining = dbnToolsFreeTierDeduct($ftUid, 'ask');
if ($ftRemaining >= 0) { header('X-Credits-Remaining: ' . $ftRemaining); }
$input = dbnToolsJsonInput(25000);
$language = dbnToolsNormalizeLanguage($input['language'] ?? 'en');

dbnToolsWithTelemetry('ask', $language, function () use ($input, $language): array {
    $question = dbnToolsString($input, 'question', 4000);
    return (new DbnLegalToolsService())->ask($question, $language);
});
