package com.sptg.third.api.feigns.grid.fallback;

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.iot.api.dto.AlarmNoticeDto;
import com.sptg.iot.api.entity.IotDevice;
import com.sptg.third.api.feigns.grid.GridIotFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zwx
 * @create 2020/11/28 20:19
 */
@Slf4j
@Component
public class GridIotFeignFallbackFactory implements FallbackFactory<GridIotFeign> {
    @Override
    public GridIotFeign create(Throwable cause) {
        return new GridIotFeign() {

            @Override
            public ResultBean<String> gridIotDeviceIncrementPush() {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<String> gridIotDeviceTotalPush() {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<String> gridIotDevicePush(List<IotDevice> iotDeviceList) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<String> gridIotDeviceHeartbeatPush(IotDevice iotDevice) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<String> gridIotDeviceStatusPush(IotDevice iotDevice) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<String> gridIotAlarmPush(List<AlarmNoticeDto> alarmNoticeDtoList) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
        };
    }
}
