"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChannelModelRepo = void 0;
exports.makeChannelModelRepo = makeChannelModelRepo;
const core_1 = require("@vived/core");
const ChannelModel_1 = require("./ChannelModel");
class ChannelModelRepo extends core_1.AppObjectEntityRepo {
}
exports.ChannelModelRepo = ChannelModelRepo;
ChannelModelRepo.type = "CHANNEL_MODEL_REPO";
ChannelModelRepo.get = (appObjects) => (0, core_1.getSingletonComponent)(ChannelModelRepo.type, appObjects);
function makeChannelModelRepo(appObject) {
    return new ChannelModelRepoImp(appObject);
}
class ChannelModelRepoImp extends ChannelModelRepo {
    get activeModel() {
        return this.memoizedIsLoading.val;
    }
    set activeModel(val) {
        this.memoizedIsLoading.val = val;
    }
    constructor(appObject) {
        super(appObject, ChannelModelRepo.type);
        this.memoizedIsLoading = new core_1.MemoizedString("", this.notifyOnChange);
        this.getChannelModel = (id, createIfMissing) => {
            let rVal = this.getForAppObject(id);
            if (rVal === undefined && createIfMissing) {
                rVal = this.channelModelFactory(id);
                this.add(rVal);
            }
            return rVal;
        };
        this.createChannelModel = (id) => {
            const idToUse = id ?? (0, core_1.generateUniqueID)();
            const object = this.channelModelFactory(idToUse);
            this.add(object);
            return object;
        };
        this.channelModelFactory = (id) => {
            const ao = this.appObjects.getOrCreate(id);
            return (0, ChannelModel_1.makeChannelModelEntity)(ao);
        };
    }
}
//# sourceMappingURL=ChannelModelRepo.js.map