package com.vetti.common.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * OAuth2.0 社交登录配置属性类
 *
 * @author vetti
 */
@Component
@ConfigurationProperties(prefix = "oauth2")
public class HotakeOAuth2Properties {

    /** Google配置 */
    private OAuthClientConfig google;

    /** Microsoft配置 */
    private OAuthClientConfig microsoft;

    /** LinkedIn配置 */
    private OAuthClientConfig linkedin;

    public OAuthClientConfig getGoogle() {
        return google;
    }

    public void setGoogle(OAuthClientConfig google) {
        this.google = google;
    }

    public OAuthClientConfig getMicrosoft() {
        return microsoft;
    }

    public void setMicrosoft(OAuthClientConfig microsoft) {
        this.microsoft = microsoft;
    }

    public OAuthClientConfig getLinkedin() {
        return linkedin;
    }

    public void setLinkedin(OAuthClientConfig linkedin) {
        this.linkedin = linkedin;
    }

    /**
     * 根据provider获取对应配置
     */
    public OAuthClientConfig getByProvider(String provider) {
        switch (provider.toLowerCase()) {
            case "google":
                return google;
            case "microsoft":
                return microsoft;
            case "linkedin":
                return linkedin;
            default:
                return null;
        }
    }

    /**
     * OAuth客户端配置
     */
    public static class OAuthClientConfig {
        /** 客户端ID */
        private String clientId;
        /** 客户端密钥 */
        private String clientSecret;
        /** 回调地址 */
        private String redirectUri;
        /** 授权范围 */
        private String scope;
        /** 授权端点 */
        private String authUri;
        /** 令牌端点 */
        private String tokenUri;
        /** 用户信息端点 */
        private String userInfoUri;

        public String getClientId() {
            return clientId;
        }

        public void setClientId(String clientId) {
            this.clientId = clientId;
        }

        public String getClientSecret() {
            return clientSecret;
        }

        public void setClientSecret(String clientSecret) {
            this.clientSecret = clientSecret;
        }

        public String getRedirectUri() {
            return redirectUri;
        }

        public void setRedirectUri(String redirectUri) {
            this.redirectUri = redirectUri;
        }

        public String getScope() {
            return scope;
        }

        public void setScope(String scope) {
            this.scope = scope;
        }

        public String getAuthUri() {
            return authUri;
        }

        public void setAuthUri(String authUri) {
            this.authUri = authUri;
        }

        public String getTokenUri() {
            return tokenUri;
        }

        public void setTokenUri(String tokenUri) {
            this.tokenUri = tokenUri;
        }

        public String getUserInfoUri() {
            return userInfoUri;
        }

        public void setUserInfoUri(String userInfoUri) {
            this.userInfoUri = userInfoUri;
        }
    }
}
