import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { BaseAppState } from "../../BaseApp";
import { Hideable } from "../../Hideable";
import { ObjectPickEntity } from "../Entities/ObjectPickEntity";
export class ValidateObjectPickUC extends 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 getSingletonComponent(ValidateObjectPickUC.type, appObjects);
    }
}
ValidateObjectPickUC.type = "ValidateObjectPickUC";
export function makeValidateObjectPickUC(appObject) {
    return new ValidateObjectPickUCImp(appObject);
}
class ValidateObjectPickUCImp extends ValidateObjectPickUC {
    get baseApp() {
        return this.getCachedSingleton(BaseAppState.type);
    }
    get objectPick() {
        return this.getCachedSingleton(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.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