package com.schisandra.auth.application.factory;

import com.schisandra.auth.application.handler.oauth.SchisandraOauthTypeHandler;
import com.schisandra.auth.application.handler.sms.SchisandraSmsTypeHandler;
import com.schisandra.auth.common.enums.OauthType;
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 OauthTypeHandlerFactory
 * @BelongsProject: schisandra-cloud-storage
 * @BelongsPackage: com.schisandra.auth.application.factory
 * @Author: landaiqing
 * @CreateTime: 2024-05-26  14:09
 * @Description: TODO
 * @Version: 1.0
 */
@Component
public class OauthTypeHandlerFactory implements InitializingBean {


    @Resource
    private List<SchisandraOauthTypeHandler> oauthTypeHandlerList;

    private HashMap<OauthType,SchisandraOauthTypeHandler> handlerMap =new HashMap<>();
    public SchisandraOauthTypeHandler getHandler(String type){
        OauthType oauthType = OauthType.getByType(type);
        return handlerMap.get(oauthType);
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        for(SchisandraOauthTypeHandler oauthTypeHandler : oauthTypeHandlerList){
            handlerMap.put(oauthTypeHandler.getHandlerType(),oauthTypeHandler);
        }
    }
}
