// tools/telemetry-health-handler.ts — SPEC-346: Handle telemetry_health tool requests.
import { checkTelemetryHealth } from '../engine/telemetry/health-checker.js';
import { compactError } from './output-formatter.js';
function statusIcon(status) {
    if (status === 'ok') {
        return '[OK]';
    }
    if (status === 'warn') {
        return '[WARN]';
    }
    if (status === 'fail') {
        return '[FAIL]';
    }
    return '[SKIP]';
}
function formatChecks(checks) {
    return checks.map((c) => `${statusIcon(c.status)} ${c.name}: ${c.detail}`).join('\n');
}
export async function handleTelemetryHealth(input) {
    try {
        const result = await checkTelemetryHealth(input.projectPath, {
            sendTestEvent: input.sendTestEvent ?? false,
        });
        const lines = [
            `## Telemetry Health — ${result.status.toUpperCase()}`,
            '',
            result.humanSummary,
            '',
            '### Checks',
            '',
            formatChecks(result.checks),
            '',
            '### Recommendation',
            '',
            result.recommendation,
        ];
        if (input.sendTestEvent === true) {
            lines.push('', '> Test diagnostic event sent — check the dashboard in 30s.');
        }
        return { content: [{ type: 'text', text: lines.join('\n') }] };
    }
    catch (err) {
        const message = err instanceof Error ? err.message : String(err);
        return compactError(`Error: ${message}`);
    }
}
//# sourceMappingURL=telemetry-health-handler.js.map