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