"use strict";
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();
    }
    async execute(args) {
        if (this.$options.markingMode) {
            await this.$markingModeService.handleMarkingModeFullDeprecation({
                projectDir: this.$projectData.projectDir,
                forceSwitch: true,
            });
            return;
        }
        if (!(await this.$updateController.shouldUpdate({
            projectDir: this.$projectData.projectDir,
            version: args[0],
        }))) {
            this.$logger.printMarkdown(`__${UpdateCommand.PROJECT_UP_TO_DATE_MESSAGE}__`);
            return;
        }
        await this.$updateController.update({
            projectDir: this.$projectData.projectDir,
            version: args[0],
            frameworkPath: this.$options.frameworkPath,
        });
    }
    async canExecute(args) {
        const shouldMigrate = await 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 !== "";
    }
}
exports.UpdateCommand = UpdateCommand;
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.";
yok_1.injector.registerCommand("update", UpdateCommand);
