// SPDX-License-Identifier: Apache-2.0
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { inject, injectable } from 'tsyringe-neo';
import { Listr, } from 'listr2';
import { InjectTokens } from '../dependency-injection/inject-tokens.js';
import { patchInject } from '../dependency-injection/container-helper.js';
let DefaultTaskList = class DefaultTaskList {
    logger;
    constructor(logger) {
        this.logger = logger;
        this.logger = patchInject(InjectTokens.SoloLogger, this.logger, this.constructor.name);
    }
    newOneShotSingleDeployTaskList(task, options, parentTask) {
        return new Listr(task, options, parentTask);
    }
    newOneShotSingleDestroyTaskList(task, options, parentTask) {
        return new Listr(task, options, parentTask);
    }
    parentTaskListMap = new Map();
    newTaskList(task, options, parentTask, commandName) {
        if (this.parentTaskListMap.has(commandName)) {
            const parentTaskList = this.parentTaskListMap.get(commandName);
            parentTaskList.children = parentTaskList.taskListWrapper.newListr(task, options);
            return parentTaskList.children;
        }
        return new Listr(task, options, parentTask);
    }
    trailingCloseFunctions = [];
    registerCloseFunction(trailingCloseFunction) {
        this.trailingCloseFunctions.push(trailingCloseFunction);
    }
    async callCloseFunctions() {
        for (const closeFunction of this.trailingCloseFunctions) {
            try {
                await closeFunction()
                    .then()
                    .catch((error) => {
                    // Log the error or handle it as needed
                    this.logger.error('Error during trailing close function:', error);
                });
            }
            catch (error) {
                // Log the error or handle it as needed
                this.logger.error('Error during trailing close function:', error);
            }
        }
        this.trailingCloseFunctions = []; // Clear the functions after execution
    }
};
DefaultTaskList = __decorate([
    injectable(),
    __param(0, inject(InjectTokens.SoloLogger)),
    __metadata("design:paramtypes", [Object])
], DefaultTaskList);
export { DefaultTaskList };
//# sourceMappingURL=default-task-list.js.map