import * as i0 from '@angular/core';
import { Pipe, Inject, NgModule } from '@angular/core';
import { NEVER } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators';
import { CommonModule } from '@angular/common';

const DATA_SOURCE_PROVIDER = 'DATA_SOURCE_PROVIDER';

class DataStreamIdToObjectPipe {
    constructor(dataSourceProvider) {
        this.dataSourceProvider = dataSourceProvider;
    }
    transform(value) {
        const stream = this.dataSourceProvider.getStream(value);
        if (!stream) {
            console.warn(`Cannot find stream with id ${value}`);
        }
        return stream;
    }
}
/** @nocollapse */ /** @nocollapse */ DataStreamIdToObjectPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamIdToObjectPipe, deps: [{ token: DATA_SOURCE_PROVIDER }], target: i0.ɵɵFactoryTarget.Pipe });
/** @nocollapse */ /** @nocollapse */ DataStreamIdToObjectPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamIdToObjectPipe, name: "dataStreamIdToObject" });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamIdToObjectPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'dataStreamIdToObject',
                }]
        }], ctorParameters: function () { return [{ type: undefined, decorators: [{
                    type: Inject,
                    args: [DATA_SOURCE_PROVIDER]
                }] }]; } });

class DataStreamIdToValueStreamPipe {
    constructor(dataSourceProvider) {
        this.dataSourceProvider = dataSourceProvider;
    }
    transform(streamId) {
        return this.dataSourceProvider.getStream(streamId).pipe(switchMap((dataStreamOrUndefined) => {
            if (!dataStreamOrUndefined) {
                console.warn(`dataStreamIdToValueStream Cannot find stream with id ${streamId}`, 'available streams', this.dataSourceProvider.getAvailableStreamIds());
                return NEVER;
            }
            else {
                console.info(`dataStreamIdToValueStream Found stream with id ${streamId}`, dataStreamOrUndefined);
                return dataStreamOrUndefined.values;
            }
        }), tap({
            complete: () => {
                console.info(`dataStreamIdToValueStream complete stream with id ${streamId}`);
            },
        }));
    }
}
/** @nocollapse */ /** @nocollapse */ DataStreamIdToValueStreamPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamIdToValueStreamPipe, deps: [{ token: DATA_SOURCE_PROVIDER }], target: i0.ɵɵFactoryTarget.Pipe });
/** @nocollapse */ /** @nocollapse */ DataStreamIdToValueStreamPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamIdToValueStreamPipe, name: "dataStreamIdToValueStream" });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamIdToValueStreamPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'dataStreamIdToValueStream',
                }]
        }], ctorParameters: function () { return [{ type: undefined, decorators: [{
                    type: Inject,
                    args: [DATA_SOURCE_PROVIDER]
                }] }]; } });

class DataStreamModule {
    static forRoot(settings) {
        return {
            ngModule: DataStreamModule,
            providers: [
                {
                    provide: DATA_SOURCE_PROVIDER,
                    useExisting: settings.dataSourceProvider,
                },
            ],
        };
    }
}
/** @nocollapse */ /** @nocollapse */ DataStreamModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
/** @nocollapse */ /** @nocollapse */ DataStreamModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamModule, declarations: [DataStreamIdToObjectPipe, DataStreamIdToValueStreamPipe], imports: [CommonModule], exports: [DataStreamIdToObjectPipe, DataStreamIdToValueStreamPipe] });
/** @nocollapse */ /** @nocollapse */ DataStreamModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamModule, imports: [[CommonModule]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DataStreamModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [DataStreamIdToObjectPipe, DataStreamIdToValueStreamPipe],
                    exports: [DataStreamIdToObjectPipe, DataStreamIdToValueStreamPipe],
                    imports: [CommonModule],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { DataStreamIdToObjectPipe, DataStreamIdToValueStreamPipe, DataStreamModule };
//# sourceMappingURL=iotize-ionic-data-stream.mjs.map
