"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubmitQuestionAnswerUC = void 0;
exports.makeSubmitQuestionAnswerUC = makeSubmitQuestionAnswerUC;
const core_1 = require("@vived/core");
const BaseApp_1 = require("../../BaseApp");
const Dispatcher_1 = require("../../Dispatcher");
const Entities_1 = require("../Entities");
class SubmitQuestionAnswerUC extends core_1.AppObjectUC {
}
exports.SubmitQuestionAnswerUC = SubmitQuestionAnswerUC;
SubmitQuestionAnswerUC.type = "SubmitQuestionAnswerUC";
SubmitQuestionAnswerUC.get = (appObjects) => (0, core_1.getSingletonComponent)(SubmitQuestionAnswerUC.type, appObjects);
function makeSubmitQuestionAnswerUC(appObject) {
    return new SubmitQuestionAnswerUCImp(appObject);
}
class SubmitQuestionAnswerUCImp extends SubmitQuestionAnswerUC {
    submitAnswer(id) {
        if (!this.questionEntity)
            return;
        if (!this.questionEntity.hasAnswer(id)) {
            this.warn("Unable to find answer by ID");
            return;
        }
        const baseApp = BaseApp_1.BaseAppState.get(this.appObject.appObjectRepo);
        if (!baseApp) {
            this.warn("Unable to find Base App");
            return;
        }
        if (baseApp.isAuthoring)
            return;
        this.questionEntity.submitAnswer(id);
        const submitResult = Dispatcher_1.SubmitResultResultUC.get(this.appObject.appObjectRepo);
        if (submitResult) {
            submitResult.submitHitResult({
                success: this.questionEntity.gotItRight,
                description: baseApp.slideText,
            });
        }
        baseApp.isReviewing = true;
    }
    constructor(appObject) {
        super(appObject, SubmitQuestionAnswerUC.type);
        this.questionEntity = appObject.getComponent(Entities_1.QuestionEntity.type);
        if (!this.questionEntity) {
            this.warn("SubmitQuestionAnswerUCImp has been added to an app object that does not have QuestionEntity");
        }
    }
}
//# sourceMappingURL=SubmitQuestionAnswerUC.js.map