"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetAnswerFeedbackUC = void 0;
exports.makeSetAnswerFeedbackUC = makeSetAnswerFeedbackUC;
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const QuestionAnswerEntity_1 = require("../Entities/QuestionAnswerEntity");
const SetAnswerFeedbackUndoRedo_1 = require("./SetAnswerFeedbackUndoRedo");
class SetAnswerFeedbackUC extends core_1.AppObjectUC {
}
exports.SetAnswerFeedbackUC = SetAnswerFeedbackUC;
SetAnswerFeedbackUC.type = "SetAnswerFeedbackUC";
function makeSetAnswerFeedbackUC(appObject) {
    return new SetAnswerFeedbackUCImp(appObject);
}
class SetAnswerFeedbackUCImp extends SetAnswerFeedbackUC {
    setFeedback(feedback) {
        if (!this.answer)
            return;
        if (this.answer.feedbackText === feedback)
            return;
        const previousFeedback = this.answer.feedbackText;
        this.answer.feedbackText = feedback;
        Dispatcher_1.DispatchStateChangeUC.get(this.appObject.appObjectRepo)?.doDispatch();
        new SetAnswerFeedbackUndoRedo_1.SetAnswerFeedbackUndoRedo(previousFeedback, this.answer.id, this.appObject.appObjectRepo);
    }
    constructor(appObject) {
        super(appObject, SetAnswerFeedbackUC.type);
        this.answer = appObject.getComponent(QuestionAnswerEntity_1.QuestionAnswerEntity.type);
        if (!this.answer) {
            this.warn("SetAnswerFeedbackUC has been added to an app object that does not have QuestionAnswerEntity");
        }
    }
}
//# sourceMappingURL=SetAnswerFeedbackUC.js.map