package com.sptg.device.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.common.core.constant.OperationConstant;
import com.sptg.device.api.dto.TimeStrategyPushTaskDto;
import com.sptg.device.api.entity.TimeStrategyPushTask;
import com.sptg.device.api.entity.TimeStrategyTaskDeviceDetails;
import com.sptg.device.api.feigns.TimeStrategyPushTaskFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * title: TimeStrategyPushTaskFallbackFactory
 * package: com.sptg.device.api.feigns.fallback
 * description:时间策略发布任务-对外服务接口容错处理
 */
@Component
@Slf4j
public class TimeStrategyPushTaskFallbackFactory implements FallbackFactory<TimeStrategyPushTaskFeign> {

    @Override
    public TimeStrategyPushTaskFeign create(Throwable cause) {
        return new TimeStrategyPushTaskFeign(){

            @Override
            public ResultBean<Page<TimeStrategyPushTask>> pagingQuery(TimeStrategyPushTaskDto dto) {
                log.error(cause.getMessage(),cause);
                return  new ResultBean<>(ResultEnum.ERROR) ;
            }

            @Override
            public ResultBean<Boolean> addEntity(TimeStrategyPushTaskDto dto) {
                log.error(cause.getMessage(),cause);
                return  new ResultBean<>(ResultEnum.ERROR) ;
            }

            @Override
            public TimeStrategyPushTask getEntityById(TimeStrategyPushTaskDto dto) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public List<Long> getFkIdListByTaskId(Long taskId) {
                log.error(cause.getMessage(),cause);
                return  new ArrayList<>(OperationConstant.ZERO);
            }

            @Override
            public ResultBean<Boolean> rollback(TimeStrategyPushTaskDto dto) {
                log.error(cause.getMessage(),cause);
                return  new ResultBean<>(ResultEnum.ERROR) ;
            }

            @Override
            public ResultBean<Boolean> updatePushStatus(TimeStrategyTaskDeviceDetails details) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
        };
    }
}
