package com.kxs.system.api.feign.config;

import com.kxs.system.api.feign.RemoteOldService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;


/**
 * KXS 旧客户端ap 远程调用配置
 *
 * @author 没秃顶的码农
 * @date 2024-03-14
 */
@Configuration
@RequiredArgsConstructor
public class KxsOldApFeignClientConfiguration {


	@Value("${kxs.old.url}")
	private String baseUrl;

	@Bean("kxsOldFeignClient")
	public WebClient oauthRequestInterceptor() {

		return WebClient.builder().baseUrl(baseUrl).build();
	}

	/**
	 * 远程老平台接口
	 * @param client 客户端
	 * @return 远程老平台接口
	 */
	@Bean
	RemoteOldService remoteOldService(@Qualifier("kxsOldFeignClient") WebClient client) {
		HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();
		return factory.createClient(RemoteOldService.class);
	}



}
