import { AppObjectUC } from "@vived/core";
import { DispatchStateChangeUC } from "../../Dispatcher";
import { QuestionAnswerEntity } from "../Entities/QuestionAnswerEntity";
import { ToggleIsCorrectUndoRedo } from "./ToggleIsCorrectUndoRedo";
export class ToggleQuestionChallengeAnswerIsCorrectUC extends AppObjectUC {
}
ToggleQuestionChallengeAnswerIsCorrectUC.type = "ToggleQuestionChallengeAnswerIsCorrect";
export function makeToggleQuestionChallengeAnswerIsCorrectUC(appObject) {
    return new ToggleQuestionChallengeAnswerIsCorrectImp(appObject);
}
class ToggleQuestionChallengeAnswerIsCorrectImp extends ToggleQuestionChallengeAnswerIsCorrectUC {
    toggleIsCorrect() {
        if (!this.answer)
            return;
        this.answer.isCorrect = !this.answer.isCorrect;
        DispatchStateChangeUC.get(this.appObject.appObjectRepo)?.doDispatch();
        new ToggleIsCorrectUndoRedo(this.answer.id, this.appObject.appObjectRepo);
    }
    constructor(appObject) {
        super(appObject, ToggleQuestionChallengeAnswerIsCorrectUC.type);
        this.answer = appObject.getComponent(QuestionAnswerEntity.type);
        if (!this.answer) {
            this.warn("ToggleQuestionChallengeAnswerIsCorrectUC has been added to an app object that does not have QuestionAnswerEntity");
        }
    }
}
//# sourceMappingURL=ToggleQuestionAnswerIsCorrect.js.map