"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StopAppBaseUC = void 0;
exports.makeStopAppUC = makeStopAppUC;
const core_1 = require("@vived/core");
const BaseApp_1 = require("../../BaseApp");
const Entities_1 = require("../Entities");
class StopAppBaseUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "STOP_APP";
        this.payloadVersion = 1;
    }
}
exports.StopAppBaseUC = StopAppBaseUC;
StopAppBaseUC.type = "StopAppBaseUC";
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 = BaseApp_1.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 Entities_1.UnsupportedRequestVersion(this.requestType, version);
            }
        };
        const handler = appObject.getComponent(Entities_1.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