package com.prolog.rdc.tms.service.message.impl;

import cn.hutool.core.util.StrUtil;
import com.prolog.rdc.tms.config.enums.MessageConfigSendTypeEnum;
import com.prolog.rdc.tms.service.message.MessageChannel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author hongbo.pan
 * @date 2022/11/17
 */
@Slf4j
@Component
public class MessageChannelFactory {

    @Autowired
    private Map<String, MessageChannel> channelMap;


    public MessageChannel getChannel(String sendType) {
        MessageConfigSendTypeEnum messageConfigSendTypeEnum = MessageConfigSendTypeEnum.getByCode(sendType);
        String channel = messageConfigSendTypeEnum.getChannel();
        if (StrUtil.isBlank(channel)) {
            channel = "defaultChannel";
        }
        log.info("topic={},channel={},sendType={}", "MessageChannelFactory", channel, sendType);
        return channelMap.get(channel);
    }
}
