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());
    });
};
import '@iotize/tap/service/impl/device';
import { defineTapPropertyExtension } from '@iotize/tap';
import { TapConfiguratorReader, TapConfiguratorWriter } from '@iotize/tap/configurator';
const ɵ0 = (context) => new TapConfiguratorExtension(context);
// export function applyConfig(this: Tap, schema: TapConfiguratorConfig) {
//     return new SchemaTapConfigurator(schema, {
//         delayMs: 400
//     }).configure(this);
// }
export const _TAP_EXTENSION_CONFIGURATOR_ = defineTapPropertyExtension('configurator', ɵ0);
/**
 * @deprecated use _TAP_EXTENSION_CONFIGURATOR_ instead
 */
export const __DEFINED_PROPERTY_GETTER_CONFIGURATOR_ = _TAP_EXTENSION_CONFIGURATOR_;
// Tap.prototype.applyConfig = applyConfig;
/**
 * Tempory class in order not to break SchemaTapConfigurator API
 */
export 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();
    }
}
export { ɵ0 };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NoZW1hLWNvbmZpZ3VyYXRpb24uanMiLCJzb3VyY2VSb290Ijoibmc6Ly9AaW90aXplL3RhcC9leHQvY29uZmlndXJhdG9yLyIsInNvdXJjZXMiOlsibGliL3NjaGVtYS1jb25maWd1cmF0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8saUNBQWlDLENBQUM7QUFFekMsT0FBTyxFQUFFLDBCQUEwQixFQUFPLE1BQU0sYUFBYSxDQUFDO0FBRTlELE9BQU8sRUFBRSxxQkFBcUIsRUFBRSxxQkFBcUIsRUFBRSxNQUFNLDBCQUEwQixDQUFDO1dBa0JwRixDQUFDLE9BQU8sRUFBRSxFQUFFLENBQUMsSUFBSSx3QkFBd0IsQ0FBQyxPQUFPLENBQUM7QUFOdEQsMEVBQTBFO0FBQzFFLGlEQUFpRDtBQUNqRCx1QkFBdUI7QUFDdkIsMEJBQTBCO0FBQzFCLElBQUk7QUFDSixNQUFNLENBQUMsTUFBTSw0QkFBNEIsR0FBRywwQkFBMEIsQ0FBQyxjQUFjLEtBQzlCLENBQUM7QUFFeEQ7O0dBRUc7QUFDSCxNQUFNLENBQUMsTUFBTSx1Q0FBdUMsR0FBRyw0QkFBNEIsQ0FBQztBQUdwRiwyQ0FBMkM7QUFFM0M7O0dBRUc7QUFDSCxNQUFNLE9BQU8sd0JBQXdCO0lBU2pDLFlBQW1CLE9BRWxCLEVBQUUsT0FBdUM7UUFGdkIsWUFBTyxHQUFQLE9BQU8sQ0FFekI7UUFDRyxJQUFJLENBQUMsa0JBQWtCLEdBQUcsSUFBSSxxQkFBcUIsQ0FDL0MsT0FBTyxDQU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