package com.sino.mci.channel.adapter.registry;

import com.sino.mci.channel.common.model.ChannelType;
import com.sino.mci.channel.common.spi.ChannelAdapter;
import org.springframework.stereotype.Component;

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

@Component
public class ChannelAdapterRegistry {

    private final Map<ChannelType, ChannelAdapter> adapters = new ConcurrentHashMap<>();

    public ChannelAdapterRegistry(List<ChannelAdapter> adapterList) {
        for (ChannelAdapter adapter : adapterList) {
            adapters.put(adapter.getChannelType(), adapter);
        }
    }

    public ChannelAdapter getAdapter(ChannelType channelType) {
        return adapters.get(channelType);
    }
}
