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