import { DispatchStateChangeUC } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { UndoRedoEntity, } from "../../UndoRedo/Entities/UndoRedoEntity";
import { QuestionEntity } from "../Entities";
export 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 = QuestionEntity.get(appObjects);
        if (!this.questionEntity) {
            appObjects.submitWarning("AddAnswerUndoRedo", "Unable to find QuestionEntity");
            return;
        }
        this.dispatchStateChange = DispatchStateChangeUC.get(appObjects);
        if (!this.dispatchStateChange) {
            appObjects.submitWarning("AddAnswerUndoRedo", "Unable to find DispatchStateChangeUC");
            return;
        }
        const undoRedo = UndoRedoEntity.get(appObjects);
        if (!undoRedo) {
            appObjects.submitWarning("AddAnswerUndoRedo", "Unable to find UndoRedoEntity");
            return;
        }
        undoRedo.submitAction(this);
    }
}
//# sourceMappingURL=AddAnswerUndoRedo.js.map