"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HasNextStateUC = void 0;
exports.makeHasNextStateUC = makeHasNextStateUC;
const core_1 = require("@vived/core");
const AppDispatcher_1 = require("../Entities/AppDispatcher");
class HasNextStateUC extends core_1.AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "HAS_NEXT_STATE";
    }
}
exports.HasNextStateUC = HasNextStateUC;
HasNextStateUC.type = "HasNextStateUC";
HasNextStateUC.get = (appObjects) => (0, core_1.getSingletonComponent)(HasNextStateUC.type, appObjects);
function makeHasNextStateUC(appObject) {
    return new DispatchStateChangeUCImp(appObject);
}
class DispatchStateChangeUCImp extends HasNextStateUC {
    constructor(appObject) {
        super(appObject, HasNextStateUC.type);
        this.requestVersion = 1;
        this.doDispatch = () => {
            return new Promise((resolve, reject) => {
                const callback = (hasNextState) => {
                    resolve(hasNextState);
                };
                const payload = {
                    callback,
                };
                if (!this.appDispatcher)
                    return reject(new Error("No host handler has been registered"));
                else {
                    this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion, payload);
                }
            });
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher_1.AppDispatcher.type);
        if (!this.appDispatcher) {
            this.warn("HasNextStateUC has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first");
            this.dispose();
        }
    }
}
//# sourceMappingURL=HasNextStateUC.js.map