"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SysInfo = void 0;
const path = require("path");
const util_1 = require("util");
const doctor_1 = require("@nativescript/doctor");
const constants_1 = require("./constants");
const verify_node_version_1 = require("./common/verify-node-version");
const decorators_1 = require("./common/decorators");
const semver = require("semver");
const yok_1 = require("./common/yok");
class SysInfo {
    constructor($fs, $hostInfo) {
        this.$fs = $fs;
        this.$hostInfo = $hostInfo;
        this.sysInfo = null;
    }
    getSysInfo(config) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!this.sysInfo) {
                const pathToNativeScriptCliPackageJson = (config && config.pathToNativeScriptCliPackageJson) ||
                    path.join(__dirname, "..", "package.json");
                const androidToolsInfo = config && config.androidToolsInfo;
                this.sysInfo = yield doctor_1.sysInfo.getSysInfo({
                    pathToNativeScriptCliPackageJson,
                    androidToolsInfo,
                });
            }
            return this.sysInfo;
        });
    }
    getXcodeVersion() {
        return doctor_1.sysInfo.getXcodeVersion();
    }
    getCocoaPodsVersion() {
        return doctor_1.sysInfo.getCocoaPodsVersion();
    }
    getJavaPath() {
        return doctor_1.sysInfo.getJavaPath();
    }
    getJavaCompilerVersion() {
        return doctor_1.sysInfo.getJavaCompilerVersion();
    }
    getJavaVersionFromPath() {
        return doctor_1.sysInfo.getJavaVersionFromPath();
    }
    getJavaVersionFromJavaHome() {
        return doctor_1.sysInfo.getJavaVersionFromJavaHome();
    }
    getSystemWarnings() {
        return __awaiter(this, void 0, void 0, function* () {
            const warnings = [];
            const macOSWarningMessage = yield this.getMacOSWarningMessage();
            if (macOSWarningMessage) {
                macOSWarningMessage.toString = function () {
                    return this.message;
                };
                warnings.push(macOSWarningMessage);
            }
            const nodeWarning = (0, verify_node_version_1.getNodeWarning)();
            if (nodeWarning) {
                nodeWarning.toString = function () {
                    return this.message;
                };
                warnings.push(nodeWarning);
            }
            return warnings;
        });
    }
    getSupportedNodeVersionRange() {
        const pathToCLIPackageJson = path.join(__dirname, "..", "package.json");
        const jsonContent = this.$fs.readJson(pathToCLIPackageJson);
        return jsonContent && jsonContent.engines && jsonContent.engines.node;
    }
    getMacOSWarningMessage() {
        return __awaiter(this, void 0, void 0, function* () {
            const macOSVersion = yield this.$hostInfo.getMacOSVersion();
            if (macOSVersion && macOSVersion < constants_1.MacOSVersions.HighSierra) {
                return {
                    message: (0, util_1.format)(constants_1.MacOSDeprecationStringFormat, macOSVersion),
                    severity: "high",
                };
            }
            return null;
        });
    }
    getXcodeWarning() {
        return __awaiter(this, void 0, void 0, function* () {
            const xcodeVersion = yield this.getXcodeVersion();
            if (xcodeVersion && semver.lt(semver.coerce(xcodeVersion), "11.0.0")) {
                const message = (0, util_1.format)(constants_1.XcodeDeprecationStringFormat, xcodeVersion);
                return message;
            }
            return null;
        });
    }
}
__decorate([
    (0, decorators_1.exported)("sysInfo")
], SysInfo.prototype, "getSystemWarnings", null);
__decorate([
    (0, decorators_1.exported)("sysInfo")
], SysInfo.prototype, "getSupportedNodeVersionRange", null);
exports.SysInfo = SysInfo;
yok_1.injector.register("sysInfo", SysInfo);
