package com.njcn.msgpush.module.push.client.factory;

import com.njcn.msgpush.module.push.client.factory.impl.AliyunProviderFactory;
import com.njcn.msgpush.module.push.client.factory.impl.TelecomProviderFactory;
import com.njcn.msgpush.module.push.client.factory.impl.UniPushProviderFactory;
import com.njcn.msgpush.module.push.enums.ProviderTypeEnum;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Component
public class MessageProviderFactoryRegistry {

    private final Map<String, MessageProviderFactory> factoryMap;

    public MessageProviderFactoryRegistry() {
        Map<String, MessageProviderFactory> factories = new HashMap<>();
        factories.put(ProviderTypeEnum.ALIYUN.getCode(), new AliyunProviderFactory());
        factories.put(ProviderTypeEnum.TELECOM.getCode(), new TelecomProviderFactory());
        factories.put(ProviderTypeEnum.UNIPUSH.getCode(), new UniPushProviderFactory());
        this.factoryMap = Collections.unmodifiableMap(factories);
    }

    public MessageProviderFactory getFactory(String providerType) {
        return factoryMap.get(providerType);
    }
}
