import { AppObjectUC } from "@vived/core";
import { AppRenderingUC } from "../../BaseApp";
import { AppHandlerEntity, UnsupportedRequestVersion, } from "../Entities";
export class StopAppBaseUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "STOP_APP";
        this.payloadVersion = 1;
    }
}
StopAppBaseUC.type = "StopAppBaseUC";
export function makeStopAppUC(appObject) {
    return new StopAppBaseUCImp(appObject);
}
class StopAppBaseUCImp extends StopAppBaseUC {
    constructor(appObject) {
        super(appObject, StopAppBaseUC.type);
        this.action = () => {
            const appObjects = this.appObject.appObjectRepo;
            const appRenderingUC = AppRenderingUC.get(appObjects);
            if (!appRenderingUC) {
                console.warn("Unable to find AppRenderingUC");
                return;
            }
            appRenderingUC.stopRendering();
        };
        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("StopAppBaseUC has been added to an app object that does not have an AppHandlerEntity. Add one first");
            return;
        }
        handler.registerRequestHandler(this);
    }
}
//# sourceMappingURL=StopAppUC.js.map