package com.schisandra.auth.application.factory;

import com.schisandra.auth.application.handler.sms.SchisandraSmsTypeHandler;
import com.schisandra.auth.common.enums.SmsSupplierType;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @Classname SmsTypeHandlerFactory
 * @BelongsProject: schisandra-cloud-storage
 * @BelongsPackage: com.schisandra.auth.application.factory
 * @Author: schisandra
 * @CreateTime: 2024-05-11  18:36
 * @Description: TODO
 * @Version: 1.0
 */
@Component
public class SmsTypeHandlerFactory implements InitializingBean {
    @Resource
    private List<SchisandraSmsTypeHandler> smsTypeHandlerList;

    private HashMap<SmsSupplierType,SchisandraSmsTypeHandler> handlerMap =new HashMap<>();

    public SchisandraSmsTypeHandler getHandler(String configId){
        SmsSupplierType smsSupplierType = SmsSupplierType.getByKey(configId);
        return handlerMap.get(smsSupplierType);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        for(SchisandraSmsTypeHandler smsTypeHandler : smsTypeHandlerList){
            handlerMap.put(smsTypeHandler.getHandlerType(),smsTypeHandler);
        }
    }
}
