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