"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runDoctorCommand = runDoctorCommand;
const control_plane_config_1 = require("../config/control-plane-config");
const health_1 = require("../core/health");
const catalog_1 = require("../i18n/catalog");
const provider_resolution_1 = require("../platform/provider-resolution");
const locale_1 = require("./locale");
const shared_1 = require("./shared");
async function runDoctorCommand(cwd) {
    let config;
    let locale = await (0, locale_1.loadRawCommandLocale)(cwd).catch(() => catalog_1.DEFAULT_APP_LOCALE);
    try {
        const loadedConfig = await (0, control_plane_config_1.loadConfig)(cwd);
        locale = loadedConfig.i18n.defaultLanguage;
        config = (0, provider_resolution_1.resolveSupportedProviders)(loadedConfig).config;
    }
    catch (error) {
        const message = error instanceof Error
            ? error.message
            : (0, catalog_1.translate)(locale, "doctor.command.loadConfigFailed");
        console.log((0, catalog_1.translate)(locale, "doctor.command.configFail", { message }));
        return 1;
    }
    const checks = await (0, shared_1.runDoctorChecks)(cwd, config, { locale });
    console.log((0, health_1.renderDoctorReport)(checks));
    return (0, health_1.hasFailure)(checks) ? 1 : 0;
}
