// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
const PLUGIN_NAME = 'ValidateOperationsPlugin';
/**
 * Core phased command plugin that provides the functionality for generating a base operation graph
 * from the set of selected projects and phases.
 */
export class ValidateOperationsPlugin {
    constructor(terminal) {
        this._terminal = terminal;
    }
    apply(hooks) {
        hooks.beforeExecuteOperations.tap(PLUGIN_NAME, this._validateOperations.bind(this));
    }
    _validateOperations(records, context) {
        const phasesByProject = new Map();
        for (const { associatedPhase, associatedProject, runner } of records.keys()) {
            if (!(runner === null || runner === void 0 ? void 0 : runner.isNoOp)) {
                // Ignore operations that aren't associated with a project or phase, or that
                // use the NullOperationRunner (i.e. - the phase doesn't do anything)
                let projectPhases = phasesByProject.get(associatedProject);
                if (!projectPhases) {
                    projectPhases = new Set();
                    phasesByProject.set(associatedProject, projectPhases);
                }
                projectPhases.add(associatedPhase);
            }
        }
        for (const [project, phases] of phasesByProject) {
            const projectConfiguration = context.projectConfigurations.get(project);
            if (projectConfiguration) {
                projectConfiguration.validatePhaseConfiguration(phases, this._terminal);
            }
        }
    }
}
//# sourceMappingURL=ValidateOperationsPlugin.js.map