package com.cico.nest.lcdp.boot.core.qxsd.infrastructure.config;

import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.common.constatnt.XlwConstants;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.qjmh.QjmhClientFeign;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.sdgk.SdgkClientFeign;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.sdgk.SdgkClientFeignIntercept;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.xlw.feign.XlwClientFeign;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.xlw.feign.intercept.XlwClientFeignIntercept;
import feign.Contract;
import feign.Feign;
import feign.Logger;
import feign.codec.Decoder;
import feign.codec.Encoder;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author zws
 * @date 2024/8/7
 */

@Configuration
@Import(FeignClientsConfiguration.class)
public class FeignConfig {
    @Resource
    private Contract contract;
    @Resource
    private Decoder decoder;
    @Resource
    private Encoder encoder;
    @Value("${qxsd.xlw.http}")
    private String xlwHttpUrl;
    @Value("${qxsd.qjmh.base-url}")
    private String qjmhBaseUrl;
    @Value("${qxsd.sdgk.base-url}")
    private String sdgkBaseUrl;

    @Bean
    public XlwClientFeign xlwClientFeign() {
        return Feign.builder()
                .logger(new Logger.JavaLogger(XlwClientFeign.class))
                .logLevel(Logger.Level.FULL)
                .contract(contract).encoder(encoder).decoder(decoder)
                .requestInterceptor(new XlwClientFeignIntercept())
                .target(XlwClientFeign.class, xlwHttpUrl);
    }

    @Bean
    public QjmhClientFeign qjmhClientFeign() {
        return Feign.builder()
                .logger(new Logger.JavaLogger(QjmhClientFeign.class))
                .logLevel(Logger.Level.FULL)
                .contract(contract).encoder(encoder).decoder(decoder)
                .target(QjmhClientFeign.class, qjmhBaseUrl);
    }


    @Bean
    public SdgkClientFeign sdgkClientFeign() {
        return Feign.builder()
                .logger(new Logger.JavaLogger(SdgkClientFeign.class))
                .logLevel(Logger.Level.FULL)
                .contract(contract).encoder(encoder).decoder(decoder)
                .requestInterceptor(new SdgkClientFeignIntercept())
                .target(SdgkClientFeign.class, sdgkBaseUrl);
    }
}
