package org.springblade.openfeign;

import org.springblade.openfeign.interceptor.FeignRequestInterceptor;
import org.springblade.openfeign.properties.OpenFeignProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import feign.Feign;
import feign.Logger;
import feign.RequestInterceptor;

/**
 * Feign 配置注册
 * https://docs.spring.io/spring-cloud-openfeign/docs/3.0.2/reference/html/
 *
 * @author wookvn
 **/
@Configuration
@EnableConfigurationProperties({OpenFeignProperties.class})
@EnableFeignClients(basePackages = "org.springblade")
@ConditionalOnClass({ Feign.class })
public class FeignAutoConfiguration {

	/**
	 * openfeign拦截器配置
	 * @return
	 */
	@Bean
	public RequestInterceptor requestInterceptor() {
		return new FeignRequestInterceptor();
	}

	/**
	 * openfeign日志配置
	 * @return
	 */
	@Bean
	Logger.Level feignLevel() {
		// 默认为NONE
		return Logger.Level.FULL;
	}

}
