"use strict";
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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceDiscovery = void 0;
const events_1 = require("events");
const constants_1 = require("../../constants");
const _ = require("lodash");
const yok_1 = require("../../yok");
class DeviceDiscovery extends events_1.EventEmitter {
    constructor() {
        super(...arguments);
        this.devices = {};
    }
    startLookingForDevices() {
        return __awaiter(this, void 0, void 0, function* () {
            return;
        });
    }
    getDevice(deviceIdentifier) {
        const device = this.devices[deviceIdentifier];
        return device;
    }
    addDevice(device) {
        this.devices[device.deviceInfo.identifier] = device;
        this.raiseOnDeviceFound(device);
    }
    updateDeviceInfo(device) {
        const existingDevice = this.devices[device.deviceInfo.identifier];
        if (existingDevice) {
            _.assign(existingDevice.deviceInfo, device.deviceInfo);
        }
        else {
            this.devices[device.deviceInfo.identifier] = device;
        }
        this.raiseOnDeviceUpdated(device);
    }
    removeDevice(deviceIdentifier) {
        const device = this.devices[deviceIdentifier];
        if (!device) {
            return;
        }
        delete this.devices[deviceIdentifier];
        this.raiseOnDeviceLost(device);
    }
    raiseOnDeviceFound(device) {
        this.emit(constants_1.DeviceDiscoveryEventNames.DEVICE_FOUND, device);
    }
    raiseOnDeviceUpdated(device) {
        this.emit(constants_1.DeviceDiscoveryEventNames.DEVICE_UPDATED, device);
    }
    raiseOnDeviceLost(device) {
        this.emit(constants_1.DeviceDiscoveryEventNames.DEVICE_LOST, device);
    }
}
exports.DeviceDiscovery = DeviceDiscovery;
yok_1.injector.register("deviceDiscovery", DeviceDiscovery);
//# sourceMappingURL=device-discovery.js.map