"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShowBabylonInspectorUC = void 0;
exports.makeShowBabylonInspectorUC = makeShowBabylonInspectorUC;
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Entities_1 = require("../Entities");
class ShowBabylonInspectorUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SHOW_BABYLON_INSPECTOR";
        this.payloadVersion = 1;
    }
}
exports.ShowBabylonInspectorUC = ShowBabylonInspectorUC;
ShowBabylonInspectorUC.type = "ShowBabylonInspectorBaseUC";
function makeShowBabylonInspectorUC(appObject) {
    return new ShowBabylonInspectorUCImp(appObject);
}
class ShowBabylonInspectorUCImp extends ShowBabylonInspectorUC {
    castPayloadV1(payload) {
        const castPayload = payload;
        if (castPayload.showBabylonInspector === undefined) {
            throw new Entities_1.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 = Babylon_1.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 Entities_1.UnsupportedRequestVersion(this.requestType, version);
            }
        };
        const handler = appObject.getComponent(Entities_1.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