package com.ningdatech.pmapi.common.config;

import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import com.ningdatech.pmapi.common.util.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

/**
 * @author CMM
 * @since 2023/02/03 09:24
 */
@Configuration
@Slf4j
public class BeanConfig {
    @Bean
    public SpringContextHolder springContextHolder() {
        return new SpringContextHolder();
    }

    @Bean("authExecutableClient")
    @DependsOn(value = "govDingProperties")
    public ExecutableClient executableAuthClientInit() {
        ExecutableClient executableClient = ExecutableClient.getInstance();
        executableClient.setAccessKey(GovDingProperties.appAuthkey);
        executableClient.setSecretKey(GovDingProperties.appAuthsecret);
        executableClient.setDomainName(GovDingProperties.domain);
        executableClient.setProtocal("https");
        executableClient.init();
        return executableClient;
    }

    @Bean("executableClient")
    @DependsOn(value = "govDingProperties")
    public ExecutableClient executableClientInit() {
        ExecutableClient executableClient = new ExecutableClient();
        executableClient.setAccessKey(GovDingProperties.appkey);
        executableClient.setSecretKey(GovDingProperties.appsecret);
        executableClient.setDomainName(GovDingProperties.domain);
        executableClient.setProtocal("https");
        executableClient.init();
        return executableClient;
    }
}
