package com.zm.order.tool.server.stream;

import com.zm.order.tool.server.stream.convert.DataStreamConverter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author nianchang
 * @date 2023/03/07 4:19 下午
 */
@Component
public class DataStreamHolder implements InitializingBean {

    @Autowired
    private List<DataStreamConverter> converterList;

    private Map<Integer, DataStreamConverter> converterMap = new HashMap<>();

    @Override
    public void afterPropertiesSet() throws Exception {
        converterList.forEach(each -> {
            converterMap.put(each.route(), each);
        });
    }

    public DataStreamConverter route(SQLCategory element) {
        return element != null ? converterMap.get(element.getCode()) : null;
    }
}
