import { __awaiter, __generator, __extends, __spread } from 'tslib';
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 { 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 __generator(this, function (_a) {
            return [2 /*return*/, new Promise((/**
                 * @param {?} resolve
                 * @return {?}
                 */
                function (resolve) { return setTimeout((/**
                 * @return {?}
                 */
                function () { return resolve(); }), ms); }))];
        });
    });
}
var VariableInteractionTesting = /** @class */ (function (_super) {
    __extends(VariableInteractionTesting, _super);
    function VariableInteractionTesting(options) {
        var _this = _super.call(this) || this;
        _this.options = options;
        _this._rawValue = Uint8Array.from([0]);
        return _this;
    }
    Object.defineProperty(VariableInteractionTesting.prototype, "id", {
        get: /**
         * @return {?}
         */
        function () {
            var _a;
            return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.identifier) || 'Unamed variable';
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @return {?}
     */
    VariableInteractionTesting.prototype.readRawInner = /**
     * @return {?}
     */
    function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, this._rawValue];
            });
        });
    };
    /**
     * @param {?} value
     * @return {?}
     */
    VariableInteractionTesting.prototype.writeRaw = /**
     * @param {?} value
     * @return {?}
     */
    function (value) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                this._rawValue = value;
                return [2 /*return*/];
            });
        });
    };
    return VariableInteractionTesting;
}(AbstractVariable));
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
 */
var  /**
 * @template T
 */
TestingScanner = /** @class */ (function () {
    function TestingScanner() {
        this.scanning = new BehaviorSubject(false);
        this._results$ = new Subject();
        this._results = [];
    }
    Object.defineProperty(TestingScanner.prototype, "isScanning", {
        get: /**
         * @return {?}
         */
        function () {
            return this.scanning.value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TestingScanner.prototype, "results", {
        get: /**
         * @return {?}
         */
        function () {
            return this._results$.asObservable();
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @param {?=} option
     * @return {?}
     */
    TestingScanner.prototype.start = /**
     * @param {?=} option
     * @return {?}
     */
    function (option) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.clearResults();
                        return [4 /*yield*/, sleep(100)];
                    case 1:
                        _a.sent();
                        if (!this.isScanning) {
                            this.scanning.next(true);
                        }
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * @return {?}
     */
    TestingScanner.prototype.stop = /**
     * @return {?}
     */
    function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, sleep(100)];
                    case 1:
                        _a.sent();
                        this.scanning.next(false);
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * @param {?} result
     * @return {?}
     */
    TestingScanner.prototype.addResult = /**
     * @param {?} result
     * @return {?}
     */
    function (result) {
        this._results.push(result);
        this._results$.next(this._results);
    };
    /**
     * @private
     * @return {?}
     */
    TestingScanner.prototype.clearResults = /**
     * @private
     * @return {?}
     */
    function () {
        this._results = [];
        this._results$.next(this._results);
    };
    return TestingScanner;
}());
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
 */
var BLEScannerTestingService = /** @class */ (function (_super) {
    __extends(BLEScannerTestingService, _super);
    function BLEScannerTestingService() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return BLEScannerTestingService;
}(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
 */
var ProtocolFactoryTestingService = /** @class */ (function () {
    function ProtocolFactoryTestingService() {
    }
    /**
     * @param {?} meta
     * @return {?}
     */
    ProtocolFactoryTestingService.prototype.create = /**
     * @param {?} meta
     * @return {?}
     */
    function (meta) {
        throw new Error("Unsupported protocol type \"" + meta.type + "\"");
    };
    /**
     * @param {?} meta
     * @return {?}
     */
    ProtocolFactoryTestingService.prototype.isValid = /**
     * @param {?} meta
     * @return {?}
     */
    function (meta) {
        return false;
    };
    return ProtocolFactoryTestingService;
}());

/**
 * @fileoverview added by tsickle
 * Generated from: lib/iotize-ionic-testing.module.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
var ScannerNotAvailable = /** @class */ (function () {
    function ScannerNotAvailable(message) {
        this.message = message;
        this.scanning = of(false);
        this.isScanning = false;
        this.results = never();
    }
    /**
     * @param {?=} option
     * @return {?}
     */
    ScannerNotAvailable.prototype.start = /**
     * @param {?=} option
     * @return {?}
     */
    function (option) {
        return Promise.reject(this.message);
    };
    /**
     * @return {?}
     */
    ScannerNotAvailable.prototype.stop = /**
     * @return {?}
     */
    function () {
        return Promise.reject(this.message);
    };
    return ScannerNotAvailable;
}());
if (false) {
    /** @type {?} */
    ScannerNotAvailable.prototype.scanning;
    /** @type {?} */
    ScannerNotAvailable.prototype.isScanning;
    /** @type {?} */
    ScannerNotAvailable.prototype.results;
    /** @type {?} */
    ScannerNotAvailable.prototype.message;
}
/** @type {?} */
var ProtocolFactoryTestingServiceProvider = {
    provide: ProtocolFactoryService,
    useClass: ProtocolFactoryTestingService
};
/**
 * @param {?} name
 * @return {?}
 */
function scannerNotAvailableFactory(name) {
    /** @type {?} */
    var factory = (/**
     * @return {?}
     */
    function () {
        /** @type {?} */
        var scanner = new ScannerNotAvailable(name + " scanner is not available for this test");
        return scanner;
    });
    return factory;
}
var ɵ0 = defaultInfoResolverConfig, ɵ1 = ({
    loginUrl: '/device/login'
}), ɵ2 = ({
    encryption: undefined,
    nfcPairing: false,
    refreshSessionState: true,
    switchProtocol: false
}), ɵ3 = scannerNotAvailableFactory('Wi-Fi'), ɵ4 = scannerNotAvailableFactory('Network');
var IotizeIonicTestingModule = /** @class */ (function () {
    function IotizeIonicTestingModule() {
    }
    /**
     * @param {?=} options
     * @return {?}
     */
    IotizeIonicTestingModule.forRoot = /**
     * @param {?=} options
     * @return {?}
     */
    function (options) {
        // const providers: Provider[] = [];
        /** @type {?} */
        var overwritesProvides = [];
        if (options === null || options === void 0 ? void 0 : options.platform) {
            overwritesProvides.push({
                provide: Platform,
                useFactory: (/**
                 * @param {?} doc
                 * @param {?} ngZone
                 * @return {?}
                 */
                function (doc, ngZone) {
                    return new TestingPlatform(doc, ngZone, options === null || options === void 0 ? void 0 : options.platform);
                }),
                deps: [DOCUMENT, NgZone]
            });
        }
        return {
            ngModule: IotizeIonicTestingModule,
            providers: __spread(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
                    ]
                },] }
    ];
    return IotizeIonicTestingModule;
}());
var TestingPlatform = /** @class */ (function (_super) {
    __extends(TestingPlatform, _super);
    function TestingPlatform(doc, zone, platformName) {
        var _this = _super.call(this, doc, zone) || this;
        _this.platformName = platformName;
        return _this;
    }
    /**
     * @param {?} platformName
     * @return {?}
     */
    TestingPlatform.prototype.is = /**
     * @param {?} platformName
     * @return {?}
     */
    function (platformName) {
        return platformName === this.platformName;
    };
    return TestingPlatform;
}(Platform));
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
 */
var WifiScannerTestingService = /** @class */ (function (_super) {
    __extends(WifiScannerTestingService, _super);
    function WifiScannerTestingService() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return WifiScannerTestingService;
}(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
