"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.runDoctorCommand = runDoctorCommand;
const bootstrap_1 = require("../bootstrap");
const runtimeGuard_1 = require("../services/runtimeGuard");
const stdio_1 = require("../io/stdio");
async function runDoctorCommand(args) {
    const { paths } = (0, bootstrap_1.bootstrap)({ envFile: args.envFile, sessionDir: args.sessionDir, requireLlm: false });
    const format = args.format ?? 'text';
    const report = await (0, stdio_1.withConsoleLogToStderr)(format !== 'text', async () => (0, runtimeGuard_1.collectDoctorReport)(paths.home));
    if (format === 'json' || format === 'ndjson') {
        console.log(JSON.stringify(report, null, format === 'json' ? 2 : 0));
        return report.ok ? 0 : 1;
    }
    printTextReport(report);
    return report.ok ? 0 : 1;
}
function printTextReport(report) {
    console.log('SmartPerfetto CLI Doctor');
    console.log(`generated  ${report.generatedAt}`);
    console.log(`home       ${report.cliHome}`);
    console.log(`runtime    ${report.runtime.kind} (${report.runtime.source})`);
    if (report.runtime.providerName) {
        console.log(`provider   ${report.runtime.providerName} (${report.runtime.providerType}, ${report.runtime.providerId})`);
    }
    console.log('');
    for (const check of report.checks) {
        const mark = check.status === 'ok' ? 'OK' : check.status === 'warn' ? 'WARN' : 'ERROR';
        console.log(`${mark.padEnd(5)} ${check.name}: ${check.message}`);
        if (check.details?.path)
            console.log(`      path: ${check.details.path}`);
    }
    console.log('');
    console.log(`capture   adb=${report.captureTools.adb.source}:${report.captureTools.adb.path}`);
    console.log(`          devices=${report.captureTools.devices.readyCount}/${report.captureTools.devices.count}`);
    console.log(`          tracebox=${report.captureTools.tracebox.source}:${report.captureTools.tracebox.path}`);
}
//# sourceMappingURL=doctor.js.map