import { AppObjectUC } from "@vived/core";
import { EmulateStylusUC } from "../../Stylus";
import { RenderToXR } from "../../XR";
import { ZSpaceEntity } from "../../zSpace";
import { AppHandlerEntity, UnsupportedRequestVersion, } from "../Entities";
export class StopZSpaceUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "STOP_ZSPACE";
        this.payloadVersion = 1;
    }
}
StopZSpaceUC.type = "StopZSpaceBaseUC";
export function makeStopZSpaceUC(appObject) {
    return new StopZSpaceUCImp(appObject);
}
class StopZSpaceUCImp extends StopZSpaceUC {
    constructor(appObject) {
        super(appObject, StopZSpaceUC.type);
        this.action = () => {
            const appObjects = this.appObject.appObjectRepo;
            const zSpaceEntity = ZSpaceEntity.get(appObjects);
            if (zSpaceEntity) {
                zSpaceEntity.enabled = false;
                zSpaceEntity.emulate = false;
            }
            else {
                appObjects.submitError("stopZSpaceAction", "No zSpace Entity Found");
                return;
            }
            const renderUC = zSpaceEntity.appObject.getComponent(RenderToXR.type);
            if (renderUC) {
                renderUC.stopRenderingXR();
            }
            else {
                appObjects.submitError("stopZSpaceAction", "No renderUC found");
                return;
            }
            const emulateStylus = EmulateStylusUC.get(appObjects);
            if (emulateStylus) {
                emulateStylus.stopEmulating();
            }
            else {
                appObjects.submitWarning("stopZSpaceAction", "EmulateStylusUC not found");
                return;
            }
        };
        this.handleRequest = (version) => {
            if (version === this.payloadVersion) {
                this.action();
            }
            else {
                throw new UnsupportedRequestVersion(this.requestType, version);
            }
        };
        const handler = appObject.getComponent(AppHandlerEntity.type);
        if (!handler) {
            this.warn("StopZSpaceBaseUC has been added to an app object that does not have an AppHandlerEntity. Add one first");
            return;
        }
        handler.registerRequestHandler(this);
    }
}
//# sourceMappingURL=StopZSpaceUC.js.map