package com.ruoyi.framework.config;

import com.ruoyi.common.config.JustAuthConfig;
import com.ruoyi.common.just.AuthAppletRequest;
import com.ruoyi.framework.handle.AuthStateRedisCache;
import lombok.Data;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthAliyunRequest;
import me.zhyd.oauth.request.AuthDingTalkRequest;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.request.AuthWeChatMpRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import javax.annotation.Resource;

/**
 * @author Duke_yzl
 * @date 20230617.01
 * @describe：
 */
@Data
@Configuration
public class JustAuthRequestConfig {

    @Resource
    private JustAuthConfig justAuthConfig;
    @Resource
    private AuthStateRedisCache authStateRedisCache;


    @Bean("weChatMpAuthRequest")
    @DependsOn("justAuthConfig")
    public AuthRequest getWeChatMpRequest() {
        JustAuthConfig.WeChatMp wxMp = justAuthConfig.getWeChatMp();
        return new AuthWeChatMpRequest(AuthConfig.builder()
                .clientId(wxMp.getClientId())
                .clientSecret(wxMp.getClientSecret())
                .redirectUri(wxMp.getRedirectUri())
                .build(),authStateRedisCache);
    }
    @Bean("dingTalkAuthRequest")
    @DependsOn("justAuthConfig")
    public AuthRequest getDingdingRequest() {
        JustAuthConfig.DingTalk dingTalk = justAuthConfig.getDingTalk();
        return new AuthDingTalkRequest(AuthConfig.builder()
                .clientId(dingTalk.getClientId())
                .clientSecret(dingTalk.getClientSecret())
                .redirectUri(dingTalk.getRedirectUri())
                .build(),authStateRedisCache);
    }

    @Bean("aliyunAuthRequest")
    @DependsOn("justAuthConfig")
    public AuthRequest getAliyunRequest() {
        JustAuthConfig.Aliyun aliyun = justAuthConfig.getAliyun();
        return new AuthAliyunRequest(AuthConfig.builder()
                .clientId(aliyun.getClientId())
                .clientSecret(aliyun.getClientSecret())
                .redirectUri(aliyun.getRedirectUri())
                .build(),authStateRedisCache);
    }


    @Bean("weChatAppletAuthRequest")
    @DependsOn("justAuthConfig")
    public AuthRequest getWeChatAppletRequest() {
        JustAuthConfig.WeChatApplet weChatApplet = justAuthConfig.getWeChatApplet();
        return new AuthAppletRequest(AuthConfig.builder()
                .clientId(weChatApplet.getClientId())
                .clientSecret(weChatApplet.getClientSecret())
                .redirectUri("http://")
                .build());
    }
}