package cn.iselab.mooctest.user.configure;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;

/**
 * @Description: 作用描述
 * @Author: xuexb
 * @CreateDate: 19-1-9$ 下午2:21$
 */
@Configuration
public class ThirdPartyAuthConfiguration {

    @Value("${github.clientId}")
    String gitHubClientId;

    @Value("${github.clientSecret}")
    String gitHubClientSecret;

    @Bean
    public RestTemplate getRestTemplate(){
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setReadTimeout(5000);
        factory.setConnectTimeout(5000);
        RestTemplate restTemplate = new RestTemplate(factory);
        return restTemplate;
    }

    @Bean
    public HttpEntity<String> jsonAcceptHeaders(){
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.set("Accept", MediaType.APPLICATION_JSON.toString());
        httpHeaders.set(HttpHeaders.ACCEPT_CHARSET, StandardCharsets.UTF_8.toString());
        HttpEntity<String> entity = new HttpEntity<>(null, httpHeaders);
        return entity;
    }

    public String getGitHubClientId() {
        return gitHubClientId;
    }

    public void setGitHubClientId(String gitHubClientId) {
        this.gitHubClientId = gitHubClientId;
    }

    public String getGitHubClientSecret() {
        return gitHubClientSecret;
    }

    public void setGitHubClientSecret(String gitHubClientSecret) {
        this.gitHubClientSecret = gitHubClientSecret;
    }
}
