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

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.iot.api.dto.DeviceStatusNoticeDto;
import com.sptg.iot.api.dto.HeartbeatNoticeDto;
import com.sptg.iot.api.dto.IotDeviceDto;
import com.sptg.iot.api.entity.IotDevice;
import com.sptg.iot.api.feigns.IotDeviceFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zwx
 * @create 2020/10/22 16:29
 */
@Slf4j
@Component
public class IotDeviceFeignFallbackFactory implements FallbackFactory<IotDeviceFeign> {
    @Override
    public IotDeviceFeign create(Throwable cause) {
        return new IotDeviceFeign() {
            @Override
            public ResultBean<Page<IotDevice>> showIotDeviceList(IotDeviceDto iotDeviceDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Page<IotDevice>> pagingQuery(IotDeviceDto iotDeviceDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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

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

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

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

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

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

            @Override
            public IotDevice getIotDeviceById(Long id) {
                log.error(cause.getMessage(), cause);
                return null;
            }

            @Override
            public IotDevice getIotDeviceByDeviceId(String deviceId) {
                log.error(cause.getMessage(), cause);
                return null;
            }

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

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

            @Override
            public ResultBean<IotDevice> deviceHeartbeatNotice(List<HeartbeatNoticeDto> heartbeatDtoList) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<IotDevice> deviceStatusNotice(DeviceStatusNoticeDto deviceStatusDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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

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

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