package com.schisandra.auth.infra.rpc;

import com.schisandra.auth.infra.entity.OauthConfigInfo;
import com.schisandra.system.api.SchisandraSystemFeignService;
import com.schisandra.system.entity.Result;
import com.schisandra.system.entity.SchisandraSysOauthDTO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Classname OauthConfigRpc
 * @BelongsProject: schisandra-cloud-storage
 * @BelongsPackage: com.schisandra.auth.infra.rpc
 * @Author: landaiqing
 * @CreateTime: 2024-05-25  23:52
 * @Description: TODO
 * @Version: 1.0
 */
@Component
public class OauthConfigRpc {
    @Resource
    private SchisandraSystemFeignService schisandraSystemFeignService;

    public OauthConfigInfo getOauthConfigInfo(String type) {
        Result<SchisandraSysOauthDTO> result = schisandraSystemFeignService.getOauthConfigByType(type);
        OauthConfigInfo oauthConfigInfo = new OauthConfigInfo();
        if (!result.getSuccess()) {
            return oauthConfigInfo;
        }
        SchisandraSysOauthDTO data = result.getData();
        oauthConfigInfo.setAgentId(data.getAgentId());
        oauthConfigInfo.setClientId(data.getClientId());
        oauthConfigInfo.setClientSecret(data.getClientSecret());
        oauthConfigInfo.setClientType(data.getClientType());
        oauthConfigInfo.setStatus(data.getStatus());
        oauthConfigInfo.setRedirectUri(data.getRedirectUri());
        oauthConfigInfo.setDomainPrefix(data.getDomainPrefix());
        oauthConfigInfo.setTenantId(data.getTenantId());
        oauthConfigInfo.setAlipayPublicKey(data.getAlipayPublicKey());
        oauthConfigInfo.setStackOverflowKey(data.getStackOverflowKey());

        return oauthConfigInfo;
    }
}
