"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AddQuestionAnswerUC = void 0;
exports.makeAddQuestionAnswerUC = makeAddQuestionAnswerUC;
exports.addQuestionAnswer = addQuestionAnswer;
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const QuestionEntity_1 = require("../Entities/QuestionEntity");
const AddAnswerUndoRedo_1 = require("./AddAnswerUndoRedo");
class AddQuestionAnswerUC extends core_1.AppObjectUC {
}
exports.AddQuestionAnswerUC = AddQuestionAnswerUC;
AddQuestionAnswerUC.type = "AddQuestionAnswerUC";
AddQuestionAnswerUC.get = (appObjects) => (0, core_1.getSingletonComponent)(AddQuestionAnswerUC.type, appObjects);
function makeAddQuestionAnswerUC(appObject) {
    return new AddQuestionAnswerUCImp(appObject);
}
function addQuestionAnswer(appObjects) {
    const uc = AddQuestionAnswerUC.get(appObjects);
    if (uc) {
        uc.addAnswer();
    }
    else {
        appObjects.submitWarning("addQuestionAnswer", "Can't find AddQuestionAnswerUC");
    }
}
class AddQuestionAnswerUCImp extends AddQuestionAnswerUC {
    addAnswer() {
        if (!this.questionEntity)
            return;
        const ans = this.questionEntity.createNewAnswer();
        Dispatcher_1.DispatchStateChangeUC.get(this.appObject.appObjectRepo)?.doDispatch();
        new AddAnswerUndoRedo_1.AddAnswerUndoRedo(ans.id, this.appObject.appObjectRepo);
    }
    constructor(appObject) {
        super(appObject, AddQuestionAnswerUC.type);
        this.questionEntity = appObject.getComponent(QuestionEntity_1.QuestionEntity.type);
        if (!this.questionEntity) {
            this.warn("AddAnswerUC has been added to an app object that does not have QuestionEntity");
        }
    }
}
//# sourceMappingURL=AddQuestionAnswerUC.js.map