import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
export class ShowSelectModelUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SHOW_SELECT_MODEL";
    }
}
ShowSelectModelUC.type = "ShowSelectModelUC";
ShowSelectModelUC.get = (appObjects) => getSingletonComponent(ShowSelectModelUC.type, appObjects);
export function makeShowSelectModelUC(appObject) {
    return new ShowSelectModelUCImp(appObject);
}
class ShowSelectModelUCImp extends ShowSelectModelUC {
    constructor(appObject) {
        super(appObject, ShowSelectModelUC.type);
        this.requestVersion = 1;
        this.doDispatch = () => {
            return new Promise((resolve, reject) => {
                const callback = (modelId, dataId) => {
                    resolve({ modelId, dataId });
                };
                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.type);
        if (!this.appDispatcher) {
            this.warn(`${ShowSelectModelUC.type} has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first`);
            this.dispose();
        }
    }
}
//# sourceMappingURL=ShowSelectModelUC.js.map