import { DOCUMENT, CommonModule } from '@angular/common';
import { 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, TAP_INFO_RESOLVER_CONFIG, TAP_CONNECTION_OPTIONS_PROVIDER, TAP_WIFI_SCANNER, TAP_BLE_SCANNER, TAP_NETWORK_SCANNER, TaskManagerUiModule, LibCommonModule } 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 { __awaiter } from 'tslib';
import { AbstractVariable } from '@iotize/tap/data';

/**
 * @fileoverview added by tsickle
 * Generated from: lib/util.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/**
 * @param {?} ms
 * @return {?}
 * @this {*}
 */
function sleep(ms) {
    return __awaiter(this, void 0, void 0, function* () {
        return new Promise((/**
         * @param {?} resolve
         * @return {?}
         */
        (resolve) => setTimeout((/**
         * @return {?}
         */
        () => resolve()), ms)));
    });
}
class VariableInteractionTesting extends AbstractVariable {
    /**
     * @param {?=} options
     */
    constructor(options) {
        super();
        this.options = options;
        this._rawValue = Uint8Array.from([0]);
    }
    /**
     * @return {?}
     */
    get id() {
        var _a;
        return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.identifier) || 'Unamed variable';
    }
    /**
     * @return {?}
     */
    readRawInner() {
        return __awaiter(this, void 0, void 0, function* () {
            return this._rawValue;
        });
    }
    /**
     * @param {?} value
     * @return {?}
     */
    writeRaw(value) {
        return __awaiter(this, void 0, void 0, function* () {
            this._rawValue = value;
        });
    }
}
if (false) {
    /**
     * @type {?}
     * @private
     */
    VariableInteractionTesting.prototype._rawValue;
    /** @type {?} */
    VariableInteractionTesting.prototype.converter;
    /** @type {?} */
    VariableInteractionTesting.prototype.options;
}

/**
 * @fileoverview added by tsickle
 * Generated from: lib/testing-scanner.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/**
 * @template T
 */
class TestingScanner {
    constructor() {
        this.scanning = new BehaviorSubject(false);
        this._results$ = new Subject();
        this._results = [];
    }
    /**
     * @return {?}
     */
    get isScanning() {
        return this.scanning.value;
    }
    /**
     * @return {?}
     */
    get results() {
        return this._results$.asObservable();
    }
    /**
     * @param {?=} option
     * @return {?}
     */
    start(option) {
        return __awaiter(this, void 0, void 0, function* () {
            this.clearResults();
            yield sleep(100);
            if (!this.isScanning) {
                this.scanning.next(true);
            }
        });
    }
    /**
     * @return {?}
     */
    stop() {
        return __awaiter(this, void 0, void 0, function* () {
            yield sleep(100);
            this.scanning.next(false);
        });
    }
    /**
     * @param {?} result
     * @return {?}
     */
    addResult(result) {
        this._results.push(result);
        this._results$.next(this._results);
    }
    /**
     * @private
     * @return {?}
     */
    clearResults() {
        this._results = [];
        this._results$.next(this._results);
    }
}
if (false) {
    /** @type {?} */
    TestingScanner.prototype.scanning;
    /**
     * @type {?}
     * @private
     */
    TestingScanner.prototype._results$;
    /**
     * @type {?}
     * @private
     */
    TestingScanner.prototype._results;
}

/**
 * @fileoverview added by tsickle
 * Generated from: lib/ble-scanner-testing.service.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
class BLEScannerTestingService extends TestingScanner {
}

/**
 * @fileoverview added by tsickle
 * Generated from: lib/protocol-factory-testing.service.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
class ProtocolFactoryTestingService {
    constructor() { }
    /**
     * @param {?} meta
     * @return {?}
     */
    create(meta) {
        throw new Error(`Unsupported protocol type "${meta.type}"`);
    }
    /**
     * @param {?} meta
     * @return {?}
     */
    isValid(meta) {
        return false;
    }
}

/**
 * @fileoverview added by tsickle
 * Generated from: lib/iotize-ionic-testing.module.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
class ScannerNotAvailable {
    /**
     * @param {?} message
     */
    constructor(message) {
        this.message = message;
        this.scanning = of(false);
        this.isScanning = false;
        this.results = never();
    }
    /**
     * @param {?=} option
     * @return {?}
     */
    start(option) {
        return Promise.reject(this.message);
    }
    /**
     * @return {?}
     */
    stop() {
        return Promise.reject(this.message);
    }
}
if (false) {
    /** @type {?} */
    ScannerNotAvailable.prototype.scanning;
    /** @type {?} */
    ScannerNotAvailable.prototype.isScanning;
    /** @type {?} */
    ScannerNotAvailable.prototype.results;
    /** @type {?} */
    ScannerNotAvailable.prototype.message;
}
/** @type {?} */
const ProtocolFactoryTestingServiceProvider = {
    provide: ProtocolFactoryService,
    useClass: ProtocolFactoryTestingService
};
/**
 * @param {?} name
 * @return {?}
 */
function scannerNotAvailableFactory(name) {
    /** @type {?} */
    const factory = (/**
     * @return {?}
     */
    () => {
        /** @type {?} */
        const scanner = new ScannerNotAvailable(`${name} scanner is not available for this test`);
        return scanner;
    });
    return factory;
}
const ɵ0 = defaultInfoResolverConfig, ɵ1 = ({
    loginUrl: '/device/login'
}), ɵ2 = ({
    encryption: undefined,
    nfcPairing: false,
    refreshSessionState: true,
    switchProtocol: false
}), ɵ3 = scannerNotAvailableFactory('Wi-Fi'), ɵ4 = scannerNotAvailableFactory('Network');
class IotizeIonicTestingModule {
    /**
     * @param {?=} options
     * @return {?}
     */
    static forRoot(options) {
        // const providers: Provider[] = [];
        /** @type {?} */
        const overwritesProvides = [];
        if (options === null || options === void 0 ? void 0 : options.platform) {
            overwritesProvides.push({
                provide: Platform,
                useFactory: (/**
                 * @param {?} doc
                 * @param {?} ngZone
                 * @return {?}
                 */
                (doc, ngZone) => {
                    return new TestingPlatform(doc, ngZone, options === null || options === void 0 ? void 0 : options.platform);
                }),
                deps: [DOCUMENT, NgZone]
            });
        }
        return {
            ngModule: IotizeIonicTestingModule,
            providers: [
                // ...providers,
                ...overwritesProvides
            ]
        };
    }
}
IotizeIonicTestingModule.decorators = [
    { type: NgModule, args: [{
                declarations: [],
                providers: [
                    ProtocolFactoryTestingServiceProvider,
                    {
                        provide: TAP_INFO_RESOLVER_CONFIG,
                        useValue: ɵ0
                    },
                    NFC,
                    {
                        provide: DEVICE_AUTH_GUARD_CONFIG,
                        useValue: (/** @type {?} */ (ɵ1))
                    },
                    {
                        provide: TAP_CONNECTION_OPTIONS_PROVIDER,
                        useValue: (/** @type {?} */ (ɵ2))
                    },
                    {
                        provide: TAP_WIFI_SCANNER,
                        useFactory: ɵ3
                    },
                    {
                        provide: TAP_BLE_SCANNER,
                        useClass: BLEScannerTestingService
                    },
                    {
                        provide: TAP_NETWORK_SCANNER,
                        useFactory: ɵ4
                    }
                ],
                imports: [],
                exports: [
                    CommonModule,
                    ReactiveFormsModule,
                    FormsModule,
                    RouterTestingModule,
                    TaskManagerUiModule,
                    LibCommonModule
                ]
            },] }
];
class TestingPlatform extends Platform {
    /**
     * @param {?} doc
     * @param {?} zone
     * @param {?} platformName
     */
    constructor(doc, zone, platformName) {
        super(doc, zone);
        this.platformName = platformName;
    }
    /**
     * @param {?} platformName
     * @return {?}
     */
    is(platformName) {
        return platformName === this.platformName;
    }
}
if (false) {
    /** @type {?} */
    TestingPlatform.prototype.platformName;
}

/**
 * @fileoverview added by tsickle
 * Generated from: lib/wifi-scanner-testing.service.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
class WifiScannerTestingService extends TestingScanner {
}

/**
 * @fileoverview added by tsickle
 * Generated from: public_api.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * Generated from: iotize-ionic-testing.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

export { BLEScannerTestingService, IotizeIonicTestingModule, ProtocolFactoryTestingService, ProtocolFactoryTestingServiceProvider, VariableInteractionTesting, WifiScannerTestingService, scannerNotAvailableFactory, sleep, TestingScanner as ɵa };
//# sourceMappingURL=iotize-ionic-testing.js.map
