import deviceClient from '@iotize/device-client.js';

var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

function commonjsRequire () {
	throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
}

function unwrapExports (x) {
	return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}

function createCommonjsModule(fn, module) {
	return module = { exports: {} }, fn(module, module.exports), module.exports;
}

function getCjsExportFromNamespace (n) {
	return n && n['default'] || n;
}

var factoryReset_1 = createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });

function factoryReset() {
    return __awaiter(this, void 0, void 0, function* () {
        // 1.1 check firmware status
        //check that IoTize FW is in Normal Mode
        let currentState = (yield this.service.firmware.getState()).body();
        if (currentState != deviceClient.FirmwareState.NORMAL) {
            throw new Error('Cannot restore factory configuration during firmware update process.');
        }
        // ==================================================================
        // 2. log
        // if (device.isAuthenticated()){
        //     throw new Error(`You must be authenticated to perform this action`);
        // }
        // ==================================================================
        // - Factory Reset ---------------------------------------------------
        (yield this.service.device.factoryReset()).successful();
    });
}
exports.factoryReset = factoryReset;
deviceClient.IoTizeDevice.prototype.factoryReset = factoryReset;

});

var factoryReset = unwrapExports(factoryReset_1);
var factoryReset_2 = factoryReset_1.factoryReset;

var public_api = createCommonjsModule(function (module, exports) {
"use strict";
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });

__export(factoryReset_1);

});

var public_api$1 = unwrapExports(public_api);

var iotizeDeviceClient_jsExtFactoryReset = createCommonjsModule(function (module, exports) {
"use strict";
/**
 * Generated bundle index. Do not edit.
 */
function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(public_api);

});

var iotizeDeviceClient_jsExtFactoryReset$1 = unwrapExports(iotizeDeviceClient_jsExtFactoryReset);

export default iotizeDeviceClient_jsExtFactoryReset$1;
//# sourceMappingURL=iotize-device-client.js-ext-factory-reset.js.map
