import '@iotize/tap/service/impl/device';
import { defineTapPropertyExtension } from '@iotize/tap';
import { TapConfiguratorWriter, TapConfiguratorReader } from '@iotize/tap/configurator';

var __awaiter = (this && this.__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());
    });
};
const ɵ0 = (context) => new TapConfiguratorExtension(context);
// export function applyConfig(this: Tap, schema: TapConfiguratorConfig) {
//     return new SchemaTapConfigurator(schema, {
//         delayMs: 400
//     }).configure(this);
// }
const _TAP_EXTENSION_CONFIGURATOR_ = defineTapPropertyExtension('configurator', ɵ0);
/**
 * @deprecated use _TAP_EXTENSION_CONFIGURATOR_ instead
 */
const __DEFINED_PROPERTY_GETTER_CONFIGURATOR_ = _TAP_EXTENSION_CONFIGURATOR_;
// Tap.prototype.applyConfig = applyConfig;
/**
 * Tempory class in order not to break SchemaTapConfigurator API
 */
class TapConfiguratorExtension {
    constructor(context, options) {
        this.context = context;
        this.configuratorWriter = new TapConfiguratorWriter(options);
        this.configuratorReader = new TapConfiguratorReader();
    }
    get tap() {
        return this.context.tap;
    }
    // get _schemaConfigurator() {
    //     const schema = new TapConfiguratorWriter(this.options);
    //     schema.tap = this.tap;
    //     return schema;
    // }
    setup(schema, options) {
        return __awaiter(this, void 0, void 0, function* () {
            const firmwareVersion = (yield this.tap.service.device.getFirmwareVersion()).body();
            return this.configuratorWriter.configure(this.tap, firmwareVersion, schema, options);
        });
    }
    setupConfigState() {
        return this.configuratorWriter.setupConfigState(this.tap);
    }
    applyConfig(newVersion = "1.0.0") {
        return this.configuratorWriter.applyConfig(this.tap, newVersion);
    }
    isConfigured() {
        return this.configuratorWriter.isConfigured(this.tap);
    }
    /**
     * Read configurations
     * Last emitter event will be the configuration keys mapping
     */
    read() {
        return this.configuratorReader.createReadOperations(this.tap).asObservable();
    }
}

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

export { _TAP_EXTENSION_CONFIGURATOR_, __DEFINED_PROPERTY_GETTER_CONFIGURATOR_ };
//# sourceMappingURL=iotize-tap-ext-configurator.js.map
