"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkFile = checkFile;
exports.checkServiceManagerAvailability = checkServiceManagerAvailability;
const promises_1 = require("node:fs/promises");
const service_manager_1 = require("../../core/service-manager");
const catalog_1 = require("../../i18n/catalog");
const check_names_1 = require("./check-names");
async function checkFile(filePath, label, missingStatus = "fail", locale = catalog_1.DEFAULT_APP_LOCALE) {
    try {
        await (0, promises_1.access)(filePath, promises_1.constants.F_OK);
        return {
            name: label,
            status: "ok",
            message: (0, catalog_1.translate)(locale, "doctor.environment.file.present", { label }),
        };
    }
    catch {
        return {
            name: label,
            status: missingStatus,
            message: (0, catalog_1.translate)(locale, "doctor.environment.file.missing", { label }),
        };
    }
}
async function checkServiceManagerAvailability(locale = catalog_1.DEFAULT_APP_LOCALE) {
    const manager = await (0, service_manager_1.detectServiceManager)({ locale });
    if (manager.supported) {
        return {
            name: (0, check_names_1.getDoctorCheckName)("serviceManager", locale),
            status: "ok",
            message: (0, catalog_1.translate)(locale, "doctor.environment.serviceManager.available", {
                description: manager.description,
            }),
        };
    }
    return {
        name: (0, check_names_1.getDoctorCheckName)("serviceManager", locale),
        status: "warning",
        message: manager.reason ??
            (0, catalog_1.translate)(locale, "doctor.environment.serviceManager.unsupported"),
    };
}
