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