function _define_property(obj, key, value) {
    if (key in obj) Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
    });
    else obj[key] = value;
    return obj;
}
class CollectionTemplateManager {
    addCollectionTemplates() {
        let templateClasses = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [];
        const newCollectionTemplateInstances = templateClasses.reduce((acc, Template)=>{
            const instance = new Template(this);
            acc[instance.name] = instance;
            return acc;
        }, {});
        Object.assign(this.collectionTemplateInstances, newCollectionTemplateInstances);
        this.dataSourceManager.getDataSources().forEach((dataSource)=>{
            const reAddCollections = dataSource.collectionManager.getCollections((collection)=>newCollectionTemplateInstances[collection.template]);
            dataSource.collectionManager.reAddCollections(reAddCollections);
        });
        return newCollectionTemplateInstances;
    }
    getCollectionTemplate(name) {
        return this.collectionTemplateInstances[name];
    }
    getCollectionTemplates(dataSourceType) {
        return Object.values(this.collectionTemplateInstances).filter((item)=>{
            if (!dataSourceType) return true;
            if (!item.supportDataSourceType && !item.notSupportDataSourceType) return true;
            if (item.supportDataSourceType) {
                var _item_supportDataSourceType;
                return null === (_item_supportDataSourceType = item.supportDataSourceType) || void 0 === _item_supportDataSourceType ? void 0 : _item_supportDataSourceType.includes(dataSourceType);
            }
            if (item.notSupportDataSourceType) {
                var _item_notSupportDataSourceType;
                return !(null === (_item_notSupportDataSourceType = item.notSupportDataSourceType) || void 0 === _item_notSupportDataSourceType ? void 0 : _item_notSupportDataSourceType.includes(dataSourceType));
            }
            return true;
        }).sort((a, b)=>(a.order || 0) - (b.order || 0));
    }
    constructor(templateClasses, dataSourceManager){
        _define_property(this, "dataSourceManager", void 0);
        _define_property(this, "collectionTemplateInstances", void 0);
        this.dataSourceManager = dataSourceManager;
        this.collectionTemplateInstances = {};
        this.addCollectionTemplates(templateClasses);
    }
}
export { CollectionTemplateManager };
