import { AppObjectUC } from "@vived/core";
import { BabylonEntity } from "../../Babylon";
import { AppHandlerEntity, UnableToParsePayload, UnsupportedRequestVersion, } from "../Entities";
export class ShowBabylonInspectorUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SHOW_BABYLON_INSPECTOR";
        this.payloadVersion = 1;
    }
}
ShowBabylonInspectorUC.type = "ShowBabylonInspectorBaseUC";
export function makeShowBabylonInspectorUC(appObject) {
    return new ShowBabylonInspectorUCImp(appObject);
}
class ShowBabylonInspectorUCImp extends ShowBabylonInspectorUC {
    castPayloadV1(payload) {
        const castPayload = payload;
        if (castPayload.showBabylonInspector === undefined) {
            throw new UnableToParsePayload(this.requestType, 1, JSON.stringify(payload));
        }
        return castPayload;
    }
    constructor(appObject) {
        super(appObject, ShowBabylonInspectorUC.type);
        this.action = (show) => {
            const appObjects = this.appObject.appObjectRepo;
            const babylon = BabylonEntity.get(appObjects);
            if (!babylon) {
                return;
            }
            babylon.showInspector = show;
        };
        this.handleRequest = (version, payload) => {
            if (version === this.payloadVersion) {
                const { showBabylonInspector } = this.castPayloadV1(payload);
                this.action(showBabylonInspector);
            }
            else {
                throw new UnsupportedRequestVersion(this.requestType, version);
            }
        };
        const handler = appObject.getComponent(AppHandlerEntity.type);
        if (!handler) {
            this.warn("ShowBabylonInspectorBaseUC has been added to an app object that does not have an AppHandlerEntity. Add one first");
            return;
        }
        handler.registerRequestHandler(this);
    }
}
//# sourceMappingURL=ShowBabylonInspectorUC.js.map