import { AppObjectEntityRepo, generateUniqueID, getSingletonComponent, MemoizedString, } from "@vived/core";
import { makeChannelModelEntity } from "./ChannelModel";
export class ChannelModelRepo extends AppObjectEntityRepo {
}
ChannelModelRepo.type = "CHANNEL_MODEL_REPO";
ChannelModelRepo.get = (appObjects) => getSingletonComponent(ChannelModelRepo.type, appObjects);
export 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 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 ?? generateUniqueID();
            const object = this.channelModelFactory(idToUse);
            this.add(object);
            return object;
        };
        this.channelModelFactory = (id) => {
            const ao = this.appObjects.getOrCreate(id);
            return makeChannelModelEntity(ao);
        };
    }
}
//# sourceMappingURL=ChannelModelRepo.js.map