import { sleep } from '@iotize/common/utility';
import { BleConfig, BleComError } from '@iotize/tap/protocol/ble/common';

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());
    });
};
class MockPeripheralAdapter {
    constructor(options = { state: 'connected', connectDelay: 100, disconnectDelay: 100 }) {
        this.options = options;
        this.services = {};
        this.services[BleConfig.services.lwm2m.service] = new MockServiceAdapter(BleConfig.services.lwm2m.service);
        this.services[BleConfig.services.fastLwm2m.service] = new MockServiceAdapter(BleConfig.services.lwm2m.service);
    }
    get state() {
        return this.options.state;
    }
    connect() {
        return __awaiter(this, void 0, void 0, function* () {
            yield sleep(this.options.connectDelay);
        });
    }
    disconnect() {
        return __awaiter(this, void 0, void 0, function* () {
            yield sleep(this.options.disconnectDelay);
        });
    }
    discoverServices() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.services;
        });
    }
    getService(uuid) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!(uuid in this.services)) {
                throw BleComError.serviceNotFound(uuid);
            }
            return this.services[uuid];
        });
    }
}
class MockServiceAdapter {
    constructor(uuid) {
        this.uuid = uuid;
    }
    getCharacteristic() {
        throw new Error(`Not implemented yet`);
    }
}

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

export { MockPeripheralAdapter, MockServiceAdapter };
//# sourceMappingURL=iotize-tap-protocol-ble-testing.js.map
