package com.simuwang.daq.service;

import cn.hutool.core.map.MapUtil;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class EmailParserFactory {

    private static final Map<String, AbstractEmailParser> ABSTRACT_PARSER_MAP = MapUtil.newHashMap();

    public EmailParserFactory(Map<String, AbstractEmailParser> abstractParserMap) {
        ABSTRACT_PARSER_MAP.putAll(abstractParserMap);
    }

    public AbstractEmailParser getInstance(Integer emailType) {
        for (Map.Entry<String, AbstractEmailParser> serviceEntry : ABSTRACT_PARSER_MAP.entrySet()) {
            AbstractEmailParser parser = serviceEntry.getValue();
            if (parser.isSupport(emailType)) {
                return parser;
            }
        }
        return null;
    }
}
