import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { BaseAppState } from "../../BaseApp";
import { SubmitResultResultUC } from "../../Dispatcher";
import { QuestionEntity } from "../Entities";
export class SubmitQuestionAnswerUC extends AppObjectUC {
}
SubmitQuestionAnswerUC.type = "SubmitQuestionAnswerUC";
SubmitQuestionAnswerUC.get = (appObjects) => getSingletonComponent(SubmitQuestionAnswerUC.type, appObjects);
export 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 = 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 = 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(QuestionEntity.type);
        if (!this.questionEntity) {
            this.warn("SubmitQuestionAnswerUCImp has been added to an app object that does not have QuestionEntity");
        }
    }
}
//# sourceMappingURL=SubmitQuestionAnswerUC.js.map