package com.yuchen.saas.park.service.factory;

import com.yuchen.saas.park.service.iot.service.IotDeviceMqttService;
import org.nest.springwrap.core.log.exception.ServiceException;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author zhouhanwei
 * @create 2024/9/12 19:04
 */
public class IotDeviceMqttFactory {

    private static final Map<String, IotDeviceMqttService> IOT_DEVICE_MQTT_SERVICE_MAP;

    static {
        IOT_DEVICE_MQTT_SERVICE_MAP = ParkApplicationContextUtil.getBeans(IotDeviceMqttService.class).values().stream().collect(Collectors.toMap(IotDeviceMqttService::type, res -> res));
    }

    public static IotDeviceMqttService getDeviceMqttService(String broadCategory) {
        IotDeviceMqttService iotDeviceMqttService = IOT_DEVICE_MQTT_SERVICE_MAP.get(broadCategory);
        if (null == iotDeviceMqttService) {
            throw new ServiceException("找不到对应对象");
        }
        return iotDeviceMqttService;
    }
}
