"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.App = void 0;
const lodash_1 = __importDefault(require("lodash"));
const tool_runner_1 = require("./tool-runner");
class App {
    static create(...args) {
        return new this(...args);
    }
    constructor(...[paths, testplane, configs]) {
        this._toolRunner = tool_runner_1.ToolRunner.create(paths, testplane, configs);
        this._browserConfigs = [];
        this._retryCache = {};
    }
    get data() {
        return this._toolRunner.tree;
    }
    async initialize() {
        return await this._toolRunner.initialize();
    }
    async finalize() {
        return this._toolRunner.finalize();
    }
    async run(tests) {
        return lodash_1.default.isEmpty(tests)
            ? this._toolRunner.run()
            : this._runWithoutRetries(tests);
    }
    async _runWithoutRetries(tests) {
        if (lodash_1.default.isEmpty(this._browserConfigs)) {
            this._browserConfigs = lodash_1.default.map(this._toolRunner.config.getBrowserIds(), (id) => this._toolRunner.config.forBrowser(id));
        }
        this._disableRetries();
        return this._toolRunner.run(tests)
            .finally(() => this._restoreRetries());
    }
    getTestsDataToUpdateRefs(imageIds = []) {
        return this._toolRunner.getTestsDataToUpdateRefs(imageIds);
    }
    getImageDataToFindEqualDiffs(imageIds = []) {
        return this._toolRunner.getImageDataToFindEqualDiffs(imageIds);
    }
    async updateReferenceImage(failedTests = []) {
        return this._toolRunner.updateReferenceImage(failedTests);
    }
    async undoAcceptImages(imageIds) {
        return this._toolRunner.undoAcceptImages(imageIds);
    }
    async findEqualDiffs(data) {
        return this._toolRunner.findEqualDiffs(data);
    }
    addClient(connection) {
        this._toolRunner.addClient(connection);
    }
    _disableRetries() {
        this._browserConfigs.forEach((broConfig) => {
            this._retryCache[broConfig.id] = broConfig.retry;
            broConfig.retry = 0;
        });
    }
    _restoreRetries() {
        this._browserConfigs.forEach((broConfig) => {
            broConfig.retry = this._retryCache[broConfig.id];
        });
    }
}
exports.App = App;
//# sourceMappingURL=app.js.map