"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToggleQuestionChallengeAnswerIsCorrectUC = void 0;
exports.makeToggleQuestionChallengeAnswerIsCorrectUC = makeToggleQuestionChallengeAnswerIsCorrectUC;
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const QuestionAnswerEntity_1 = require("../Entities/QuestionAnswerEntity");
const ToggleIsCorrectUndoRedo_1 = require("./ToggleIsCorrectUndoRedo");
class ToggleQuestionChallengeAnswerIsCorrectUC extends core_1.AppObjectUC {
}
exports.ToggleQuestionChallengeAnswerIsCorrectUC = ToggleQuestionChallengeAnswerIsCorrectUC;
ToggleQuestionChallengeAnswerIsCorrectUC.type = "ToggleQuestionChallengeAnswerIsCorrect";
function makeToggleQuestionChallengeAnswerIsCorrectUC(appObject) {
    return new ToggleQuestionChallengeAnswerIsCorrectImp(appObject);
}
class ToggleQuestionChallengeAnswerIsCorrectImp extends ToggleQuestionChallengeAnswerIsCorrectUC {
    toggleIsCorrect() {
        if (!this.answer)
            return;
        this.answer.isCorrect = !this.answer.isCorrect;
        Dispatcher_1.DispatchStateChangeUC.get(this.appObject.appObjectRepo)?.doDispatch();
        new ToggleIsCorrectUndoRedo_1.ToggleIsCorrectUndoRedo(this.answer.id, this.appObject.appObjectRepo);
    }
    constructor(appObject) {
        super(appObject, ToggleQuestionChallengeAnswerIsCorrectUC.type);
        this.answer = appObject.getComponent(QuestionAnswerEntity_1.QuestionAnswerEntity.type);
        if (!this.answer) {
            this.warn("ToggleQuestionChallengeAnswerIsCorrectUC has been added to an app object that does not have QuestionAnswerEntity");
        }
    }
}
//# sourceMappingURL=ToggleQuestionAnswerIsCorrect.js.map