package org.springblade.modules.app.config;

import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

@Component
public class GeTuiConfig {
    @Autowired
    private RemoteConfigProperties remoteConfigProperties;

    @Bean
    @DependsOn("remoteConfigProperties")
    public PushApi geTuiPushApiCreate() {
        // 设置httpClient最大连接数，当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
        System.setProperty(remoteConfigProperties.getMaxConnections(), remoteConfigProperties.getMaxConnectionsNum());
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        //填写应用配置
        apiConfiguration.setAppId(remoteConfigProperties.getAppId());
        apiConfiguration.setAppKey(remoteConfigProperties.getAppKey());
        apiConfiguration.setMasterSecret(remoteConfigProperties.getMasterSecret());
        // 实例化ApiHelper对象，用于创建接口对象
        ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
        // 创建对象
        return apiHelper.creatApi(PushApi.class);
    }
}
