"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module WorkflowTask
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskManager = exports.Task = void 0;
/* eslint-disable deprecation/deprecation */
const ItemDefBase_1 = require("../shared/ItemDefBase");
const UiFramework_1 = require("../UiFramework");
const Workflow_1 = require("./Workflow");
/** Task class.
 * A Task is a specific piece of work to accomplish.
 * A Task refers to a Frontstage to activate.
 * @internal
 * @deprecated in 3.0. Task is obsolete.
 */
class Task extends ItemDefBase_1.ItemDefBase {
    constructor(taskProps) {
        super(taskProps);
        this.taskId = taskProps.id;
        this.primaryStageId = taskProps.primaryStageId;
    }
    get id() {
        return this.taskId;
    }
    get isActive() {
        let isActive = false;
        if (Workflow_1.WorkflowManager.activeWorkflow && Workflow_1.WorkflowManager.activeWorkflow.activeTask === this)
            isActive = true;
        return isActive;
    }
    set isActive(_) {
        // do nothing - needed because subclassing from ItemDefBase
    }
    async onActivated() {
        const frontstage = await UiFramework_1.UiFramework.frontstages.getFrontstageDef(this.primaryStageId);
        if (frontstage)
            await UiFramework_1.UiFramework.frontstages.setActiveFrontstageDef(frontstage);
    }
}
exports.Task = Task;
// -----------------------------------------------------------------------------
/** Task Manager class.
 * @internal
 * @deprecated in 3.0. TaskManager is obsolete.
 */
class TaskManager {
    static loadTasks(taskListDef) {
        this.loadTaskDefs(taskListDef.tasks);
    }
    static loadTaskDefs(taskDefs) {
        taskDefs.map((taskDef, _index) => {
            this.loadTaskDef(taskDef);
        });
    }
    static loadTaskDef(taskDef) {
        const task = new Task(taskDef);
        this.addTask(taskDef.id, task);
    }
    static findTask(taskId) {
        return this._tasks.get(taskId);
    }
    static addTask(taskId, task) {
        this._tasks.set(taskId, task);
    }
}
exports.TaskManager = TaskManager;
TaskManager._tasks = new Map();
//# sourceMappingURL=Task.js.map