"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.UpdateCommand = void 0;
const yok_1 = require("../common/yok");
class UpdateCommand {
    constructor($devicePlatformsConstants, $updateController, $migrateController, $options, $errors, $logger, $projectData, $markingModeService) {
        this.$devicePlatformsConstants = $devicePlatformsConstants;
        this.$updateController = $updateController;
        this.$migrateController = $migrateController;
        this.$options = $options;
        this.$errors = $errors;
        this.$logger = $logger;
        this.$projectData = $projectData;
        this.$markingModeService = $markingModeService;
        this.allowedParameters = [];
        this.$projectData.initializeProjectData();
    }
    execute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            if (this.$options.markingMode) {
                // ns update --markingMode
                yield this.$markingModeService.handleMarkingModeFullDeprecation({
                    projectDir: this.$projectData.projectDir,
                    forceSwitch: true,
                });
                return;
            }
            if (!(yield this.$updateController.shouldUpdate({
                projectDir: this.$projectData.projectDir,
                version: args[0],
            }))) {
                this.$logger.printMarkdown(`__${UpdateCommand.PROJECT_UP_TO_DATE_MESSAGE}__`);
                return;
            }
            yield this.$updateController.update({
                projectDir: this.$projectData.projectDir,
                version: args[0],
                frameworkPath: this.$options.frameworkPath,
            });
        });
    }
    canExecute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            const shouldMigrate = yield this.$migrateController.shouldMigrate({
                projectDir: this.$projectData.projectDir,
                platforms: [
                    this.$devicePlatformsConstants.Android,
                    this.$devicePlatformsConstants.iOS,
                ],
                loose: true,
            });
            if (shouldMigrate) {
                this.$errors.fail(UpdateCommand.SHOULD_MIGRATE_PROJECT_MESSAGE);
            }
            return args.length < 2 && this.$projectData.projectDir !== "";
        });
    }
}
UpdateCommand.SHOULD_MIGRATE_PROJECT_MESSAGE = 'This project is not compatible with the current NativeScript version and cannot be updated. Use "ns migrate" to make your project compatible.';
UpdateCommand.PROJECT_UP_TO_DATE_MESSAGE = "This project is up to date.";
exports.UpdateCommand = UpdateCommand;
yok_1.injector.registerCommand("update", UpdateCommand);
//# sourceMappingURL=update.js.map