import { DispatchStateChangeUC } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { UndoRedoEntity, } from "../../UndoRedo/Entities/UndoRedoEntity";
import { QuestionEntity } from "../Entities";
export class SetAnswerTextUndoRedo {
    constructor(initialText, answerID, appObjects) {
        this.initialText = initialText;
        this.answerID = answerID;
        this.finalText = "";
        this.undoAction = () => {
            if (!this.questionEntity || !this.dispatchStateChange)
                return;
            if (!this.answer)
                return;
            this.answer.text = this.initialText;
            this.dispatchStateChange.doDispatch();
        };
        this.redoAction = () => {
            if (!this.questionEntity || !this.dispatchStateChange)
                return;
            if (!this.answer)
                return;
            this.answer.text = this.finalText;
            this.dispatchStateChange.doDispatch();
        };
        this.questionEntity = QuestionEntity.get(appObjects);
        if (!this.questionEntity) {
            appObjects.submitWarning("SetAnswerTextUndoRedo", "Unable to find QuestionEntity");
            return;
        }
        this.answer = this.questionEntity.getAnswer(this.answerID);
        if (!this.answer) {
            appObjects.submitWarning("SetAnswerTextUndoRedo", "Unable to get answer by ID");
            return;
        }
        this.finalText = this.answer.text;
        this.dispatchStateChange = DispatchStateChangeUC.get(appObjects);
        if (!this.dispatchStateChange) {
            appObjects.submitWarning("SetAnswerTextUndoRedo", "Unable to find DispatchStateChangeUC");
            return;
        }
        const undoRedo = UndoRedoEntity.get(appObjects);
        if (!undoRedo) {
            appObjects.submitWarning("SetAnswerTextUndoRedo", "Unable to find UndoRedoEntity");
            return;
        }
        undoRedo.submitAction(this);
    }
}
//# sourceMappingURL=SetAnswerTextUndoRedo.js.map