package cn.lihongjie.coal.emDevice;

import cn.lihongjie.coal.emDevice.client.DustApi;

import com.fasterxml.jackson.databind.ObjectMapper;

import feign.Feign;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration public class DustClientConfiguration {

    @Autowired
    DustConfig dustConfig;
    @Autowired ObjectMapper objectMapper;

    @Bean
    DustApi dustApi(){

        DustApi target = Feign.builder()
         .encoder(new JacksonEncoder(objectMapper))
                .decoder(new JacksonDecoder(objectMapper))

        .target(DustApi.class, dustConfig.getUrl());
        log.info("dust api url: {}", dustConfig.getUrl());
        return target;
    }

}
