import { DOCUMENT, CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { Injectable, NgZone, NgModule } from '@angular/core';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { NFC } from '@ionic-native/nfc/ngx';
import { Platform } from '@ionic/angular';
import { ProtocolFactoryService, TaskManagerUiModule, LibCommonModule, TAP_INFO_RESOLVER_CONFIG, TAP_CONNECTION_OPTIONS_PROVIDER, TAP_WIFI_SCANNER, TAP_BLE_SCANNER, TAP_NETWORK_SCANNER } from '@iotize/ionic';
import { DEVICE_AUTH_GUARD_CONFIG } from '@iotize/ionic/auth';
import { defaultInfoResolverConfig } from '@iotize/ionic/config';
import { BehaviorSubject, Subject, of, never } from 'rxjs';
import { sleep as sleep$1 } from '@iotize/common/utility';
import { Dialogs } from '@ionic-native/dialogs/ngx';
import { AbstractVariable } from '@iotize/tap/data';

class TestingScanner {
    constructor() {
        this.scanning = new BehaviorSubject(false);
        this._results$ = new Subject();
        this._results = [];
    }
    get isScanning() {
        return this.scanning.value;
    }
    get results() {
        return this._results$.asObservable();
    }
    async start(option) {
        this.clearResults();
        await sleep$1(100);
        if (!this.isScanning) {
            this.scanning.next(true);
        }
    }
    async stop() {
        await sleep$1(100);
        this.scanning.next(false);
    }
    addResult(result) {
        this._results.push(result);
        this._results$.next(this._results);
    }
    clearResults() {
        this._results = [];
        this._results$.next(this._results);
    }
}

class BLEScannerTestingService extends TestingScanner {
}
/** @nocollapse */ /** @nocollapse */ BLEScannerTestingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: BLEScannerTestingService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
/** @nocollapse */ /** @nocollapse */ BLEScannerTestingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: BLEScannerTestingService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: BLEScannerTestingService, decorators: [{
            type: Injectable
        }] });

class ProtocolFactoryTestingService {
    constructor() { }
    create(meta) {
        throw new Error(`Unsupported protocol type "${meta.type}"`);
    }
    isValid(meta) {
        return false;
    }
}
/** @nocollapse */ /** @nocollapse */ ProtocolFactoryTestingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ProtocolFactoryTestingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
/** @nocollapse */ /** @nocollapse */ ProtocolFactoryTestingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ProtocolFactoryTestingService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: ProtocolFactoryTestingService, decorators: [{
            type: Injectable
        }], ctorParameters: function () { return []; } });

class ScannerNotAvailable {
    constructor(message) {
        this.message = message;
        this.scanning = of(false);
        this.isScanning = false;
        this.results = never();
    }
    start(option) {
        return Promise.reject(this.message);
    }
    stop() {
        return Promise.reject(this.message);
    }
}
const ProtocolFactoryTestingServiceProvider = {
    provide: ProtocolFactoryService,
    useClass: ProtocolFactoryTestingService,
};
function scannerNotAvailableFactory(name) {
    const factory = () => {
        const scanner = new ScannerNotAvailable(`${name} scanner is not available for this test`);
        return scanner;
    };
    return factory;
}
class IotizeIonicTestingModule {
    static forRoot(options) {
        // const providers: Provider[] = [];
        const overwritesProvides = [];
        if (options?.platform) {
            overwritesProvides.push({
                provide: Platform,
                useFactory: (doc, ngZone) => {
                    return new TestingPlatform(doc, ngZone, options?.platform);
                },
                deps: [DOCUMENT, NgZone],
            });
        }
        return {
            ngModule: IotizeIonicTestingModule,
            providers: [
                // ...providers,
                ...overwritesProvides,
            ],
        };
    }
}
/** @nocollapse */ /** @nocollapse */ IotizeIonicTestingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: IotizeIonicTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
/** @nocollapse */ /** @nocollapse */ IotizeIonicTestingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: IotizeIonicTestingModule, exports: [CommonModule,
        ReactiveFormsModule,
        FormsModule,
        RouterTestingModule,
        TaskManagerUiModule,
        LibCommonModule] });
/** @nocollapse */ /** @nocollapse */ IotizeIonicTestingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: IotizeIonicTestingModule, providers: [
        BLEScannerTestingService,
        ProtocolFactoryTestingServiceProvider,
        Dialogs,
        {
            provide: TAP_INFO_RESOLVER_CONFIG,
            useValue: defaultInfoResolverConfig,
        },
        NFC,
        {
            provide: DEVICE_AUTH_GUARD_CONFIG,
            useValue: {
                loginUrl: '/device/login',
            },
        },
        {
            provide: TAP_CONNECTION_OPTIONS_PROVIDER,
            useValue: {
                encryption: undefined,
                nfcPairing: false,
                refreshSessionState: true,
                switchProtocol: false,
            },
        },
        {
            provide: TAP_WIFI_SCANNER,
            useFactory: scannerNotAvailableFactory('Wi-Fi'),
        },
        {
            provide: TAP_BLE_SCANNER,
            useClass: BLEScannerTestingService,
        },
        {
            provide: TAP_NETWORK_SCANNER,
            useFactory: scannerNotAvailableFactory('Network'),
        },
    ], imports: [[], CommonModule,
        ReactiveFormsModule,
        FormsModule,
        RouterTestingModule,
        TaskManagerUiModule,
        LibCommonModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: IotizeIonicTestingModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [],
                    providers: [
                        BLEScannerTestingService,
                        ProtocolFactoryTestingServiceProvider,
                        Dialogs,
                        {
                            provide: TAP_INFO_RESOLVER_CONFIG,
                            useValue: defaultInfoResolverConfig,
                        },
                        NFC,
                        {
                            provide: DEVICE_AUTH_GUARD_CONFIG,
                            useValue: {
                                loginUrl: '/device/login',
                            },
                        },
                        {
                            provide: TAP_CONNECTION_OPTIONS_PROVIDER,
                            useValue: {
                                encryption: undefined,
                                nfcPairing: false,
                                refreshSessionState: true,
                                switchProtocol: false,
                            },
                        },
                        {
                            provide: TAP_WIFI_SCANNER,
                            useFactory: scannerNotAvailableFactory('Wi-Fi'),
                        },
                        {
                            provide: TAP_BLE_SCANNER,
                            useClass: BLEScannerTestingService,
                        },
                        {
                            provide: TAP_NETWORK_SCANNER,
                            useFactory: scannerNotAvailableFactory('Network'),
                        },
                    ],
                    imports: [],
                    exports: [
                        CommonModule,
                        ReactiveFormsModule,
                        FormsModule,
                        RouterTestingModule,
                        TaskManagerUiModule,
                        LibCommonModule,
                    ],
                }]
        }] });
class TestingPlatform extends Platform {
    constructor(doc, zone, platformName) {
        super(doc, zone);
        this.platformName = platformName;
    }
    is(platformName) {
        return platformName === this.platformName;
    }
}

class WifiScannerTestingService extends TestingScanner {
}

async function sleep(ms) {
    return new Promise((resolve) => setTimeout((value) => resolve(value), ms));
}
class VariableInteractionTesting extends AbstractVariable {
    constructor(options) {
        super();
        this.options = options;
        this._rawValue = Uint8Array.from([0]);
    }
    get id() {
        return this.options?.identifier || 'Unamed variable';
    }
    async readRawInner() {
        return this._rawValue;
    }
    async writeRaw(value) {
        this._rawValue = value;
    }
}

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

export { BLEScannerTestingService, IotizeIonicTestingModule, ProtocolFactoryTestingService, ProtocolFactoryTestingServiceProvider, VariableInteractionTesting, WifiScannerTestingService, scannerNotAvailableFactory, sleep };
//# sourceMappingURL=iotize-ionic-testing.mjs.map
