"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const Log_1 = require("../core/Log");
const ScriptModuleManager_1 = require("../manager/ScriptModuleManager");
const VsCodeFileManager_1 = require("../manager/VsCodeFileManager");
const MinEngineVersionManager_1 = require("../manager/MinEngineVersionManager");
const BaseGameVersionManager_1 = require("../manager/BaseGameVersionManager");
const BehaviorPackEntityTypeManager_1 = require("../manager/BehaviorPackEntityTypeManager");
const BehaviorPackItemTypeManager_1 = require("../manager/BehaviorPackItemTypeManager");
class ProjectUpdateRunner {
    constructor(project) {
        this.project = project;
    }
    createUpdaters() {
        return [
            new ScriptModuleManager_1.default(),
            new VsCodeFileManager_1.default(),
            new MinEngineVersionManager_1.default(),
            new BaseGameVersionManager_1.default(),
            new BehaviorPackEntityTypeManager_1.default(),
            new BehaviorPackItemTypeManager_1.default(),
        ];
    }
    async updateProject(includeUpdaters, excludeUpdaters) {
        const updaters = this.createUpdaters();
        const results = [];
        if (!this.project) {
            Log_1.default.throwUnexpectedUndefined("PURUP");
            return;
        }
        for (let i = 0; i < updaters.length; i++) {
            const updater = updaters[i];
            const updaterIds = updater.getUpdateIds();
            for (let j = 0; j < updaterIds.length; j++) {
                if ((!includeUpdaters || includeUpdaters.includes(updater.id)) &&
                    (!excludeUpdaters || !excludeUpdaters.includes(updater.id))) {
                    const localResults = await updater.update(this.project, updaterIds[j]);
                    results.push(...localResults);
                }
            }
        }
        return results;
    }
    async update(updaterId, updaterIndex) {
        const updaters = this.createUpdaters();
        const allResults = [];
        if (!this.project) {
            Log_1.default.throwUnexpectedUndefined("PURU");
            return [];
        }
        for (let i = 0; i < updaters.length; i++) {
            const updater = updaters[i];
            if (updater.id === updaterId) {
                const results = await updater.update(this.project, updaterIndex);
                for (const result of results) {
                    allResults.push(result);
                }
            }
        }
        return allResults;
    }
}
exports.default = ProjectUpdateRunner;

//# sourceMappingURL=../maps/updates/ProjectUpdateRunner.js.map
