import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { DispatchStateChangeUC } from "../../Dispatcher";
import { QuestionEntity } from "../Entities/QuestionEntity";
import { AddAnswerUndoRedo } from "./AddAnswerUndoRedo";
export class AddQuestionAnswerUC extends AppObjectUC {
}
AddQuestionAnswerUC.type = "AddQuestionAnswerUC";
AddQuestionAnswerUC.get = (appObjects) => getSingletonComponent(AddQuestionAnswerUC.type, appObjects);
export function makeAddQuestionAnswerUC(appObject) {
    return new AddQuestionAnswerUCImp(appObject);
}
export 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();
        DispatchStateChangeUC.get(this.appObject.appObjectRepo)?.doDispatch();
        new AddAnswerUndoRedo(ans.id, this.appObject.appObjectRepo);
    }
    constructor(appObject) {
        super(appObject, AddQuestionAnswerUC.type);
        this.questionEntity = appObject.getComponent(QuestionEntity.type);
        if (!this.questionEntity) {
            this.warn("AddAnswerUC has been added to an app object that does not have QuestionEntity");
        }
    }
}
//# sourceMappingURL=AddQuestionAnswerUC.js.map