"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AddAnswerUndoRedo = void 0;
const DispatchStateChangeUC_1 = require("../../Dispatcher/UC/DispatchStateChangeUC");
const UndoRedoEntity_1 = require("../../UndoRedo/Entities/UndoRedoEntity");
const Entities_1 = require("../Entities");
class AddAnswerUndoRedo {
    constructor(answerID, appObjects) {
        this.answerID = answerID;
        this.undoAction = () => {
            if (!this.questionEntity || !this.dispatchStateChange)
                return;
            this.questionEntity.removeAnswer(this.answerID);
            this.dispatchStateChange.doDispatch();
        };
        this.redoAction = () => {
            if (!this.questionEntity || !this.dispatchStateChange)
                return;
            const answer = this.questionEntity.answerFactory(this.answerID);
            this.questionEntity.addAnswer(answer);
            this.dispatchStateChange.doDispatch();
        };
        this.questionEntity = Entities_1.QuestionEntity.get(appObjects);
        if (!this.questionEntity) {
            appObjects.submitWarning("AddAnswerUndoRedo", "Unable to find QuestionEntity");
            return;
        }
        this.dispatchStateChange = DispatchStateChangeUC_1.DispatchStateChangeUC.get(appObjects);
        if (!this.dispatchStateChange) {
            appObjects.submitWarning("AddAnswerUndoRedo", "Unable to find DispatchStateChangeUC");
            return;
        }
        const undoRedo = UndoRedoEntity_1.UndoRedoEntity.get(appObjects);
        if (!undoRedo) {
            appObjects.submitWarning("AddAnswerUndoRedo", "Unable to find UndoRedoEntity");
            return;
        }
        undoRedo.submitAction(this);
    }
}
exports.AddAnswerUndoRedo = AddAnswerUndoRedo;
//# sourceMappingURL=AddAnswerUndoRedo.js.map