"use strict";
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 = {};
    }
    async startLookingForDevices() {
        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);
