package org.springblade.system.bladeuserex.social.ctwing;

import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.AuthRequest;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.system.bladeuserex.social.AuthCtwingRequest;
import org.springblade.system.bladeuserex.social.SocialConfig;

public class AuthRequestUtil {

    private static SocialConfig socialConfig;

    static {
        socialConfig = SpringUtil.getBean(SocialConfig.class);
    }

    /**
     * 根据具体的授权来源，获取授权请求工具类
     *
     * @param source
     * @return
     */
    public static AuthRequest getAuthRequest(String source) {
        AuthRequest authRequest = null;
        switch (source.toUpperCase()) {
            case "CTWING":
                authRequest = new AuthCtwingRequest(AuthConfig.builder()
                        .clientId(CtwingAuthConstants.APP_ID)
                        .clientSecret(CtwingAuthConstants.APP_SECRET)
                        .redirectUri(socialConfig.getRedirectUri())
                        .build());
                break;
            default:
                break;
        }
        if (null == authRequest) {
            throw new AuthException("未获取到有效的Auth配置");
        }
        return authRequest;
    }
}
