package cn.com.taiji.beidou.ship.config;

import cn.com.taiji.beidou.ship.feign.FastjsonFeignDecoder;
import cn.com.taiji.beidou.ship.feign.FastjsonFeignEncoder;
import cn.com.taiji.beidou.ship.feign.OpenServiceFeign;
import com.alibaba.fastjson2.JSONObject;
import feign.Feign;
import feign.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class OpenFeignConfig {

    private String url="http://47.100.82.30";

    //@ConditionalOnProperty(value = "true")
    @Bean
    OpenServiceFeign openServiceFeign() {
        return Feign.builder()
                .decoder(new FastjsonFeignDecoder())
                .encoder(new FastjsonFeignEncoder())
                .logLevel(Logger.Level.FULL)
                .logger(this.getLogger())
                .target(OpenServiceFeign.class, this.url);
    }

    public Logger getLogger() {
        return new Logger() {
            @Override
            protected void log(String s, String s1, Object... objects) {
                log.debug("OpenFeignConfig >>>> OpenFeign日志：\n{}", JSONObject.toJSONString(objects));
            }
        };
    }
}
