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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2NoZW1hLWNvbmZpZ3VyYXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9leHQvY29uZmlndXJhdG9yL3NyYy9saWIvc2NoZW1hLWNvbmZpZ3VyYXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsT0FBTyxpQ0FBaUMsQ0FBQztBQUV6QyxPQUFPLEVBQUUsMEJBQTBCLEVBQU8sTUFBTSxhQUFhLENBQUM7QUFFOUQsT0FBTyxFQUNMLHFCQUFxQixFQUNyQixxQkFBcUIsR0FDdEIsTUFBTSwwQkFBMEIsQ0FBQztXQW1CaEMsQ0FBQyxPQUFPLEVBQUUsRUFBRSxDQUFDLElBQUksd0JBQXdCLENBQUMsT0FBTyxDQUFDO0FBUHBELDBFQUEwRTtBQUMxRSxpREFBaUQ7QUFDakQsdUJBQXVCO0FBQ3ZCLDBCQUEwQjtBQUMxQixJQUFJO0FBQ0osTUFBTSxDQUFDLE1BQU0sNEJBQTRCLEdBQUcsMEJBQTBCLENBQ3BFLGNBQWMsS0FFZixDQUFDO0FBRUY7O0dBRUc7QUFDSCxNQUFNLENBQUMsTUFBTSx1Q0FBdUMsR0FDbEQsNEJBQTRCLENBQUM7QUFFL0IsMkNBQTJDO0FBRTNDOztHQUVHO0FBQ0gsTUFBTSxPQUFPLHdCQUF3QjtJQVFuQyxZQUNTLE9BRU4sRUFDRCxPQUF1QztRQUhoQyxZQUFPLEdBQVAsT0FBTyxDQUViO1FBR0QsSUFBSSxDQUFDLGtCQUFrQixHQUFHLElBQUkscUJBQXFCLENBQ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