package com.hdkj.lt.feign.fallback;

import com.alibaba.fastjson.JSON;
import com.hdkj.lt.feign.ICityFeederTopoApiClient;
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;


/**
 * @author Annie
 */
@Slf4j
@Component
public class CityFeederTopoApiClientFallBack implements FallbackFactory<ICityFeederTopoApiClient> {

    @Override
    public ICityFeederTopoApiClient create(Throwable cause) {
        return new ICityFeederTopoApiClient() {
            @Override
            public ApiResponse<List<String>> getCityFeederSvg() {
                return ApiResponse.fail(String.format("远程调用服务获取线路SVG图片异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<Object> doCityFeederTopo(List<String> list) {
                log.error("request params: {}", JSON.toJSONString(list));
                return ApiResponse.fail(String.format("远程调用服务处理拓扑数据异常：%s", cause.getMessage()));
            }

            @Override
            public ApiResponse<String> sendMessage2LineFile(String topoVersion) {
                log.error("request params: {}", topoVersion);
                return ApiResponse.fail(String.format("远程调用服务发送消息处理线路SVG异常：%s", cause.getMessage()));
            }
        };
    }
}
