package com.hdkj.lt.feign.fallback;

import com.alibaba.fastjson.JSON;
import com.hdkj.lt.feign.ISvgGenerationApiClient;
import com.hdkj.lt.modle.dto.svg.DynamicSvgDTO;
import com.hdkj.lt.modle.dto.svg.DynamicSvgDetailDTO;
import com.hdkj.lt.modle.vo.svg.DynamicSvgVO;
import com.hdkj.hussar.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author wcx
 * @Date 2025/6/30 11:17
 * @Version 1.0
 */
@Slf4j
@Component
public class SvgGenerationApiClientFallBack implements FallbackFactory<ISvgGenerationApiClient> {

    @Override
    public ISvgGenerationApiClient create(Throwable cause) {
        return new ISvgGenerationApiClient() {
            @Override
            public ApiResponse<DynamicSvgVO> queryDynamicSvg(DynamicSvgDTO dynamicSvgDTO) {
                log.error("SVG动态成图服务 request params: {}", JSON.toJSONString(dynamicSvgDTO));
                return ApiResponse.fail(String.format("远程调用SVG动态成图服务异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<DynamicSvgVO> queryDynamicSvgDetail(DynamicSvgDetailDTO dynamicSvgDetailDTO) {
                log.error("SVG详图动态成图服务 request params: {}", JSON.toJSONString(dynamicSvgDetailDTO));
                return ApiResponse.fail(String.format("远程调用SVG详图动态成图服务异常：%s", cause.getMessage()));
            }
        };
    }
}
