import { DispatchStateChangeUC } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { UndoRedoEntity, } from "../../UndoRedo/Entities/UndoRedoEntity";
import { QuestionEntity } from "../Entities";
export class DeleteAnswerUndoRedo {
    constructor(answer, appObjects) {
        this.undoAction = () => {
            if (!this.questionEntity || !this.dispatchStateChange)
                return;
            const answer = this.questionEntity.answerFactory(this.id);
            answer.feedbackText = this.feedback;
            answer.text = this.text;
            answer.isCorrect = this.isCorrect;
            this.questionEntity.addAnswer(answer);
            this.dispatchStateChange.doDispatch();
        };
        this.redoAction = () => {
            if (!this.questionEntity || !this.dispatchStateChange)
                return;
            this.questionEntity.removeAnswer(this.id);
            this.dispatchStateChange.doDispatch();
        };
        const { id, feedbackText, text, isCorrect } = answer;
        this.id = id;
        this.text = text;
        this.feedback = feedbackText;
        this.isCorrect = isCorrect;
        this.questionEntity = QuestionEntity.get(appObjects);
        if (!this.questionEntity) {
            appObjects.submitWarning("DeleteAnswerUndoRedo", "Unable to find QuestionEntity");
            return;
        }
        this.dispatchStateChange = DispatchStateChangeUC.get(appObjects);
        if (!this.dispatchStateChange) {
            appObjects.submitWarning("DeleteAnswerUndoRedo", "Unable to find DispatchStateChangeUC");
            return;
        }
        const undoRedo = UndoRedoEntity.get(appObjects);
        if (!undoRedo) {
            appObjects.submitWarning("DeleteAnswerUndoRedo", "Unable to find UndoRedoEntity");
            return;
        }
        undoRedo.submitAction(this);
    }
}
//# sourceMappingURL=DeleteAnswerUndoRedo.js.map