package com.hdkj.lt.feign.fallback;

import com.alibaba.fastjson.JSON;
import com.hdkj.lt.feign.ILineSvgFileApiClient;
import com.hdkj.lt.modle.dto.file.LineSvgFileBase;
import com.hdkj.lt.modle.dto.file.LineSvgFileGetDTO;
import com.hdkj.lt.modle.dto.svg.StationSvgGenerationDTO;
import com.hdkj.lt.modle.dto.svg.SvgGenerationDTO;
import com.hdkj.lt.modle.vo.svg.LineFileInfoVO;
import com.hdkj.lt.modle.vo.svg.StationFileInfoVO;
import com.hdkj.hussar.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description
 * @Author wcx
 * @Date 2025/6/3 10:14
 * @Version 1.0
 */
@Slf4j
@Component
public class LineSvgFileApiClientFallBack implements FallbackFactory<ILineSvgFileApiClient> {

    @Override
    public ILineSvgFileApiClient create(Throwable cause) {
        return new ILineSvgFileApiClient() {
            @Override
            public ApiResponse<List<LineSvgFileGetDTO>> getLineByVersion(LineSvgFileBase lineSvgFile) {
                log.error("request params: {}", JSON.toJSONString(lineSvgFile));
                return ApiResponse.fail(String.format("远程调用服务获取线路异动信息异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<byte[]> getLineFileInfo(LineSvgFileGetDTO lineSvgFile) {
                log.error("request params: {}", JSON.toJSONString(lineSvgFile));
                return ApiResponse.fail(String.format("远程调用服务获取文件流信息异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<List<LineFileInfoVO>> lineDynamicSvgSave(SvgGenerationDTO svgGeneration) {
                log.error("request params: {}", JSON.toJSONString(svgGeneration));
                return ApiResponse.fail(String.format("线路远程调用服务保存动态SVG文件异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<List<StationFileInfoVO>> stationDynamicSvgSave(StationSvgGenerationDTO stationSvgDTO) {
                log.error("request params: {}", JSON.toJSONString(stationSvgDTO));
                return ApiResponse.fail(String.format("变电站远程调用服务保存动态SVG文件异常：%s", cause.getMessage()));
            }
        };
    }
}
