"use strict";
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.MarkingModeService = void 0;
const os_1 = require("os");
const constants_1 = require("../constants");
const yok_1 = require("../common/yok");
const semver = require("semver/preload");
const MARKING_MODE_PROP = "markingMode";
const MARKING_MODE_FULL_DEPRECATION_MSG = `In the current version of NativeScript "${MARKING_MODE_PROP}:${"full" /* MarkingMode.Full */}" is no longer supported.`;
class MarkingModeService {
    constructor($logger, $projectConfigService, $projectHelper, $projectDataService) {
        this.$logger = $logger;
        this.$projectConfigService = $projectConfigService;
        this.$projectHelper = $projectHelper;
        this.$projectDataService = $projectDataService;
    }
    handleMarkingModeFullDeprecation(options) {
        return __awaiter(this, void 0, void 0, function* () {
            const markingModeValue = this.$projectConfigService.getValue("android.markingMode");
            const { skipWarnings, forceSwitch } = options;
            if (forceSwitch) {
                yield this.setMarkingMode("none" /* MarkingMode.None */);
                return;
            }
            if (!skipWarnings && (markingModeValue === null || markingModeValue === void 0 ? void 0 : markingModeValue.toLowerCase()) !== "none" /* MarkingMode.None */) {
                // only warn if runtime is less than 7.0.0-rc.5 - where the default has been changed to None
                // if version is null - we are about to add the latest runtime, so no need to warn
                const { version } = this.$projectDataService.getRuntimePackage(this.$projectHelper.projectDir, "android" /* PlatformTypes.android */);
                const isMarkingModeFullDefault = version && semver.lt(semver.coerce(version), "7.0.0-rc.5");
                if (isMarkingModeFullDefault) {
                    this.showMarkingModeFullWarning();
                }
            }
        });
    }
    setMarkingMode(newMode) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.$projectConfigService.setValue("android.markingMode", newMode);
        });
    }
    showMarkingModeFullWarning() {
        const markingModeFullWarning = `You are using the deprecated "${MARKING_MODE_PROP}:${"full" /* MarkingMode.Full */}".${os_1.EOL}${os_1.EOL}${MARKING_MODE_FULL_DEPRECATION_MSG}${os_1.EOL}${os_1.EOL}You should update your marking mode by executing 'ns update --markingMode'.`;
        this.$logger.warn(markingModeFullWarning, {
            [constants_1.LoggerConfigData.wrapMessageWithBorders]: true,
        });
    }
}
exports.MarkingModeService = MarkingModeService;
yok_1.injector.register("markingModeService", MarkingModeService);
//# sourceMappingURL=marking-mode-service.js.map