"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const helpers = require("../common/helpers");
function RunTestCommandFactory(platform) {
    return function RunTestCommand($options, $testExecutionService, $projectData, $analyticsService, $platformEnvironmentRequirements) {
        $projectData.initializeProjectData();
        $analyticsService.setShouldDispose($options.justlaunch || !$options.watch);
        const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: $options.release });
        this.execute = (args) => $testExecutionService.startTestRunner(platform, $projectData, projectFilesConfig);
        this.canExecute = (args) => canExecute({ $platformEnvironmentRequirements, $projectData, $options, platform });
        this.allowedParameters = [];
    };
}
$injector.registerCommand("dev-test|android", RunTestCommandFactory('android'));
$injector.registerCommand("dev-test|ios", RunTestCommandFactory('iOS'));
function RunKarmaTestCommandFactory(platform) {
    return function RunKarmaTestCommand($options, $testExecutionService, $projectData, $analyticsService, $platformEnvironmentRequirements) {
        $projectData.initializeProjectData();
        $analyticsService.setShouldDispose($options.justlaunch || !$options.watch);
        const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: $options.release });
        this.execute = (args) => $testExecutionService.startKarmaServer(platform, $projectData, projectFilesConfig);
        this.canExecute = (args) => canExecute({ $platformEnvironmentRequirements, $projectData, $options, platform });
        this.allowedParameters = [];
    };
}
function canExecute(input) {
    return __awaiter(this, void 0, void 0, function* () {
        const { $platformEnvironmentRequirements, $projectData, $options, platform } = input;
        const output = yield $platformEnvironmentRequirements.checkEnvironmentRequirements({
            platform,
            projectDir: $projectData.projectDir,
            options: $options,
            notConfiguredEnvOptions: {
                hideSyncToPreviewAppOption: true,
                hideCloudBuildOption: true
            }
        });
        return output.canExecute;
    });
}
$injector.registerCommand("test|android", RunKarmaTestCommandFactory('android'));
$injector.registerCommand("test|ios", RunKarmaTestCommandFactory('iOS'));
