package com.njcn.device.pq.api.fallback;

import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.device.biz.utils.DeviceEnumUtil;
import com.njcn.device.pq.api.TerminalBaseClient;
import com.njcn.device.pq.api.TransformerClient;
import com.njcn.device.pq.pojo.dto.transformer.EntityLogicDTO;
import com.njcn.device.pq.pojo.po.Line;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2022年02月14日 14:03
 */
@Slf4j
@Component
public class TransformerClientFallbackFactory implements FallbackFactory<TransformerClient> {
    @Override
    public TransformerClient create(Throwable throwable) {
        //判断抛出异常是否为解码器抛出的业务异常
        Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
        if (throwable.getCause() instanceof BusinessException) {
            BusinessException businessException = (BusinessException) throwable.getCause();
            exceptionEnum = DeviceEnumUtil.getExceptionEnum(businessException.getResult());
        }
        Enum<?> finalExceptionEnum = exceptionEnum;
        return new TransformerClient()
        {

            @Override
            public HttpResult<List<EntityLogicDTO>> getLogic() {
                return null;
            }
        };


    }
}
