package com.sptg.device.api.feigns.fallback;

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.device.api.entity.Device;
import com.sptg.device.api.entity.MqConf;
import com.sptg.device.api.feigns.DeviceRegisterFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * title: DeviceRegisterFeignFallbackFactory
 * package: com.sptg.device.api.feigns.fallback
 * description:
 */
@Component
@Slf4j
public class DeviceRegisterFeignFallbackFactory implements FallbackFactory<DeviceRegisterFeign> {

    @Override
    public DeviceRegisterFeign create(Throwable cause) {
        return new DeviceRegisterFeign() {
            @Override
            public ResultBean<Device> getConnection(Device device) {
                log.error(cause.getMessage(),cause);
            return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<MqConf> getDHConnection() {
                log.error(cause.getMessage(),cause);
            return new ResultBean<>(ResultEnum.ERROR);
            }
        };
//        return (device) -> {
//            log.error(cause.getMessage(),cause);
//            return new ResultBean<>(ResultEnum.ERROR);
//        };
    }
}
