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

import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.statistics.api.dto.StatisticsAdPushDto;
import com.sptg.statistics.api.entity.StatisticsAdPush;
import com.sptg.statistics.api.feigns.StatisticsAdPushFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * title: StatisticsFeignFallbackFactory
 * package: com.sptg.statistics.api.feigns.fallback
 * description: 广告发布统计服务容错处理
 *
 *                
 *                 
 */
@Component
@Slf4j
public class StatisticsAdPushFeignFallbackFactory implements FallbackFactory<StatisticsAdPushFeign> {

    @Override
    public StatisticsAdPushFeign create(Throwable cause) {
        return new StatisticsAdPushFeign(){
            @Override
            public ResultBean<Boolean> addAdPush(StatisticsAdPush statisticsAdPush) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> addAdPushList(List<StatisticsAdPush> statisticsAdPushList) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Map<String, Object>> statisticsAdPushTotal(StatisticsAdPushDto statisticsAdPushDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Map<String, Object>> statisticsCurrentMonthAdPushTotal(StatisticsAdPushDto statisticsAdPushDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<List<Map<String, Object>>> statisticsAdPushAndExposure(StatisticsAdPushDto statisticsAdPushDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }


            @Override
            public List<Map<String, Object>> statisticsAdPushAndExposureByArea(StatisticsAdPushDto statisticsAdPushDto) {
                log.error(cause.getMessage(),cause);
                return new ArrayList<>(OperationConstant.ZERO);
            }

            @Override
            public Long statisticsAdPushCount(StatisticsAdPushDto statisticsAdPushDto) {
                log.error(cause.getMessage(),cause);
                return 0L;
            }

            @Override
            public ResultBean<Map<String, Long>> getAdPushAccount(StatisticsAdPushDto statisticsAdPushDto) {
                return null;
            }
        };
    }
}
