package com.usky.transfer.service.mqtt;


import com.usky.transfer.service.vo.MqttBaseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 中间处理消息转发
 */
@Service
public class SimpleContext {
    @Autowired
    private final Map<String, MqttStrategy> strategyMap = new ConcurrentHashMap<>();

    public SimpleContext(Map<String, MqttStrategy> strategyMap) {
        strategyMap.forEach(this.strategyMap::put);
    }

    public String getResource(MqttBaseVO mqttBaseVO) {
        return strategyMap.get(mqttBaseVO.getDescribe()).disposeMessage(mqttBaseVO);
    }
}