package com.ycwl.basic.integration.common.config;

import com.ycwl.basic.integration.common.exception.FeignErrorDecoder;
import feign.RequestInterceptor;
import feign.codec.ErrorDecoder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@RequiredArgsConstructor
public class FeignConfig {

    private final FeignErrorDecoder feignErrorDecoder;

    @Bean
    public ErrorDecoder errorDecoder() {
        return feignErrorDecoder;
    }

    @Bean
    public RequestInterceptor requestInterceptor() {
        return template -> {
            template.header("Accept", "application/json");
            template.header("Content-Type", "application/json");
            // 可以在这里添加统一的鉴权头
            // template.header("Authorization", "Bearer " + getToken());
        };
    }
}