"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidateQuestionChallengeStateImp = exports.ValidateQuestionChallengeStateUC = void 0;
exports.makeValidateQuestionChallengeStateUC = makeValidateQuestionChallengeStateUC;
const core_1 = require("@vived/core");
const BaseApp_1 = require("../../BaseApp");
const Entities_1 = require("../Entities");
class ValidateQuestionChallengeStateUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.SLIDE_TEXT_CANNOT_BE_FALSY = "Slide text is required.";
        this.IF_QUESTION_AT_LEAST_TWO_ANSWERS = "A question must have at lest two answers.";
        this.QUESTION_CHALLENGE_NO_CORRECT_ANSWER = "At least one answer must be correct.";
        this.ANSWER_STRING_CANNOT_BE_0_CHARACTERS = "Answer text is required.";
        this.FEEDBACK_STRING_CANNOT_BE_LONGER_THAN_200_CHARACTERS = "Answer feedback may not exceed 200 characters.";
        this.ANSWER_STRING_CANNOT_BE_LONGER_THAN_40_CHARACTERS = "Answer text may not exceed 40 characters.";
    }
}
exports.ValidateQuestionChallengeStateUC = ValidateQuestionChallengeStateUC;
ValidateQuestionChallengeStateUC.type = "ValidateQuestionChallengeStateUC";
ValidateQuestionChallengeStateUC.get = (appObjects) => (0, core_1.getSingletonComponent)(ValidateQuestionChallengeStateUC.type, appObjects);
function makeValidateQuestionChallengeStateUC(appObject) {
    return new ValidateQuestionChallengeStateImp(appObject);
}
class ValidateQuestionChallengeStateImp extends ValidateQuestionChallengeStateUC {
    validate() {
        if (!this.baseAppState)
            return;
        if (!this.questionEntity)
            return;
        if (!this.baseAppState.slideText) {
            return this.SLIDE_TEXT_CANNOT_BE_FALSY;
        }
        if (this.questionEntity.getAllAnswers().length < 2) {
            return this.IF_QUESTION_AT_LEAST_TWO_ANSWERS;
        }
        let emptyAnswerTest = false;
        let hasCorrect = false;
        let hasLongFeedback = false;
        let hasLongText = false;
        this.questionEntity.getAllAnswers().forEach((ans) => {
            if (ans.text === "") {
                emptyAnswerTest = true;
            }
            if (ans.text.length > 40) {
                hasLongText = true;
            }
            if (ans.feedbackText.length > 200) {
                hasLongFeedback = true;
            }
            if (ans.isCorrect) {
                hasCorrect = true;
            }
        });
        if (!hasCorrect) {
            return this.QUESTION_CHALLENGE_NO_CORRECT_ANSWER;
        }
        if (emptyAnswerTest) {
            return this.ANSWER_STRING_CANNOT_BE_0_CHARACTERS;
        }
        if (hasLongFeedback) {
            return this.FEEDBACK_STRING_CANNOT_BE_LONGER_THAN_200_CHARACTERS;
        }
        if (hasLongText) {
            return this.ANSWER_STRING_CANNOT_BE_LONGER_THAN_40_CHARACTERS;
        }
        return;
    }
    constructor(appObject) {
        super(appObject, ValidateQuestionChallengeStateUC.type);
        this.baseAppState = BaseApp_1.BaseAppState.get(this.appObjects);
        if (!this.baseAppState) {
            this.warn("ToggleQuestionChallengeAnswerIsCorrectUC has been added to an app object that does not have BaseAppSateEntity");
            return;
        }
        this.questionEntity = Entities_1.QuestionEntity.get(this.appObjects);
        if (!this.questionEntity) {
            this.warn("ToggleQuestionChallengeAnswerIsCorrectUC has been added to an app object that does not have QuestionEntity");
            return;
        }
    }
}
exports.ValidateQuestionChallengeStateImp = ValidateQuestionChallengeStateImp;
//# sourceMappingURL=ValidateQuestionChallengeStateUC.js.map