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

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.ad.api.dto.AdPushTaskDto;
import com.sptg.ad.api.entity.AdPushContent;
import com.sptg.ad.api.entity.AdPushTask;
import com.sptg.ad.api.entity.AdPushTaskDetails;
import com.sptg.ad.api.entity.AdPushThresholdValue;
import com.sptg.ad.api.feigns.AdPushTaskFeign;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * title: AdPushTaskFeignFallbackFactory
 * package: com.sptg.ad.api.feigns.fallback
 * description: 广告类容接口容错处理
 *
 *               
 *                 
 */
@Slf4j
@Component
public class AdPushTaskFeignFallbackFactory implements FallbackFactory<AdPushTaskFeign> {
    @Override
    public AdPushTaskFeign create(Throwable cause) {
        return new AdPushTaskFeign() {
            @Override
            public ResultBean<Page<AdPushTask>> showAdPushTaskList(AdPushTaskDto adPushTaskDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> addAdPushTask(AdPushTask adPushTask) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> cancelAdPushTask(Long id) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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

            @Override
            public ResultBean<Boolean> manuallyIssued(Long id) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public AdPushContent getPushContentByTask(Long taskId, String code) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public List<AdPushTaskDetails> getAdPushTaskDetailsByTaskId(Long id) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public List<AdPushContent> getAdPushContentsByTaskId(Long id) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public ResultBean<Boolean> adIssued(Long deviceId) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public AdPushThresholdValue getAdPushThresholdValue(AdPushThresholdValue adPushThresholdValue) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public ResultBean<Boolean> savePushThresholdValue(AdPushThresholdValue adPushThresholdValue) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public int getValidAdPushCountDevice(Long deviceId) {
                log.error(cause.getMessage(),cause);
                return 0;
            }
        };
    }
}
