"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidateObjectPickUC = void 0;
exports.makeValidateObjectPickUC = makeValidateObjectPickUC;
const core_1 = require("@vived/core");
const BaseApp_1 = require("../../BaseApp");
const Hideable_1 = require("../../Hideable");
const ObjectPickEntity_1 = require("../Entities/ObjectPickEntity");
class ValidateObjectPickUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.OBJECT_PICK_CHALLENGE_NO_SLIDE_TEXT = "A question in the slide text is required.";
        this.OBJECT_PICK_ENTITY_SHOULD_HAVE_AT_LEAST_ONE_ID = "Object Pick Entity should have at least one ID.";
        this.OBJECT_PICK_ENTITY_SHOULD_HAVE_AT_LEAST_ONE_VISIBLE_OBJECT = "Object Pick Entity should have at least one visible object ID.";
    }
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(ValidateObjectPickUC.type, appObjects);
    }
}
exports.ValidateObjectPickUC = ValidateObjectPickUC;
ValidateObjectPickUC.type = "ValidateObjectPickUC";
function makeValidateObjectPickUC(appObject) {
    return new ValidateObjectPickUCImp(appObject);
}
class ValidateObjectPickUCImp extends ValidateObjectPickUC {
    get baseApp() {
        return this.getCachedSingleton(BaseApp_1.BaseAppState.type);
    }
    get objectPick() {
        return this.getCachedSingleton(ObjectPickEntity_1.ObjectPickEntity.type);
    }
    constructor(appObject) {
        super(appObject, ValidateObjectPickUC.type);
        this.validateObjectPick = () => {
            if (!this.baseApp || !this.objectPick)
                return null;
            if (!this.baseApp.slideText) {
                return this.OBJECT_PICK_CHALLENGE_NO_SLIDE_TEXT;
            }
            if (this.objectPick.correctObjectIds.length < 1) {
                return this.OBJECT_PICK_ENTITY_SHOULD_HAVE_AT_LEAST_ONE_ID;
            }
            if (this.objectPick.correctObjectIds.length > 0) {
                let objectsShown = false;
                this.objectPick.correctObjectIds.forEach((id) => {
                    const hideable = this.appObjects.getAppObjectComponent(id, Hideable_1.Hideable.type);
                    if (!hideable) {
                        objectsShown = true;
                    }
                    else if (!hideable.isHidden) {
                        objectsShown = true;
                    }
                });
                if (!objectsShown) {
                    return this.OBJECT_PICK_ENTITY_SHOULD_HAVE_AT_LEAST_ONE_VISIBLE_OBJECT;
                }
            }
            return null;
        };
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=ValidateObjectPickUC.js.map