import * as __WEBPACK_EXTERNAL_MODULE__collection_index_mjs__ from "../collection/index.mjs";
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 DataSource {
    get app() {
        return this.dataSourceManager.app;
    }
    get key() {
        return this.options.key;
    }
    get displayName() {
        return this.options.displayName;
    }
    get status() {
        return this.options.status;
    }
    get errorMessage() {
        return this.options.errorMessage;
    }
    get collections() {
        return this.collectionManager.getCollections() || [];
    }
    getOptions() {
        return this.options;
    }
    setOptions(options) {
        Object.assign(this.options, options);
    }
    getOption(key) {
        return this.options[key];
    }
    addReloadCallback(callback) {
        if (this.reloadCallbacks.includes(callback)) return;
        this.reloadCallbacks.push(callback);
    }
    removeReloadCallback(callback) {
        this.reloadCallbacks = this.reloadCallbacks.filter((cb)=>cb !== callback);
    }
    async reload() {
        const dataSource = await this.getDataSource();
        this.setOptions(dataSource);
        this.collectionManager.setCollections(dataSource.collections || []);
        this.reloadCallbacks.forEach((callback)=>callback(dataSource.collections));
        return this.options;
    }
    constructor(options, dataSourceManager){
        _define_property(this, "options", void 0);
        _define_property(this, "dataSourceManager", void 0);
        _define_property(this, "collectionManager", void 0);
        _define_property(this, "reloadCallbacks", void 0);
        this.options = options;
        this.dataSourceManager = dataSourceManager;
        this.reloadCallbacks = [];
        this.collectionManager = new __WEBPACK_EXTERNAL_MODULE__collection_index_mjs__.CollectionManager(options.collections, this);
    }
}
class LocalDataSource extends DataSource {
    getDataSource() {
        return {
            collections: this.collections
        };
    }
}
export { DataSource, LocalDataSource };
