package com.njcn.harmonic.api.fallback;

import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.device.biz.utils.DeviceEnumUtil;
import com.njcn.harmonic.api.HarmDataFeignClient;
import com.njcn.harmonic.api.RStatLimitRateDClient;
import com.njcn.harmonic.pojo.param.HistoryHarmParam;
import com.njcn.harmonic.pojo.param.RStatLimitQueryParam;
import com.njcn.harmonic.pojo.param.StatSubstationBizBaseParam;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.harmonic.pojo.po.day.RStatLimitTargetDPO;
import com.njcn.harmonic.pojo.vo.RStatLimitTargetVO;
import com.njcn.influx.pojo.dto.HarmHistoryDataDTO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2023年07月21日 14:31
 */
@Slf4j
@Component
public class RStatLimitRateDFeignClientFallbackFactory implements FallbackFactory<RStatLimitRateDClient> {
    @Override
    public RStatLimitRateDClient create(Throwable throwable) {
        //判断抛出异常是否为解码器抛出的业务异常
        Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
        if (throwable.getCause() instanceof BusinessException) {
            BusinessException businessException = (BusinessException) throwable.getCause();
            exceptionEnum = DeviceEnumUtil.getExceptionEnum(businessException.getResult());
        }
        Enum<?> finalExceptionEnum = exceptionEnum;
        return new RStatLimitRateDClient() {


            @Override
            public HttpResult<List<RStatLimitRateDPO>> monitorIdsGetLimitInfo(RStatLimitQueryParam rStatLimitQueryParam) {
                log.error("{}异常，降级处理，异常为：{}", "获取指定日期超标监测点详细信息", throwable.toString());
                return new HttpResult<>(CommonResponseEnum.FAIL.getCode(),CommonResponseEnum.FAIL.getMessage());
            }

            @Override
            public HttpResult<List<RStatLimitTargetDPO>> monitorIdsGetLimitTargetInfo(RStatLimitQueryParam rStatLimitQueryParam) {
                log.error("{}异常，降级处理，异常为：{}", "获取指定日期超标监测点详细信息", throwable.toString());
                return new HttpResult<>(CommonResponseEnum.FAIL.getCode(),CommonResponseEnum.FAIL.getMessage());
            }

            @Override
            public HttpResult<List<RStatLimitTargetVO>> monitorOverLimitDays(RStatLimitQueryParam rStatLimitQueryParam) {
                log.error("{}异常，降级处理，异常为：{}", "按日期查询监测点各指标越限天数", throwable.toString());
                return new HttpResult<>(CommonResponseEnum.FAIL.getCode(),CommonResponseEnum.FAIL.getMessage());
            }

            @Override
            public HttpResult<List<RStatLimitRateDPO>> getOverData(String lineId, String startTime, String endTime, Integer type) {
                log.error("{}异常，降级处理，异常为：{}", "查询单监测点超标数据", throwable.toString());
                return new HttpResult<>(CommonResponseEnum.FAIL.getCode(),CommonResponseEnum.FAIL.getMessage());
            }
        };
    }
}
