package com.njcn.csharmonic.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.csharmonic.api.EventUserFeignClient;
import com.njcn.csharmonic.param.CsEventUserQueryParam;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author xy
 */
@Slf4j
@Component
public class EventUserFeignClientFallbackFactory implements FallbackFactory<EventUserFeignClient> {
    @Override
    public EventUserFeignClient create(Throwable cause) {
        //判断抛出异常是否为解码器抛出的业务异常
        Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
        if (cause.getCause() instanceof BusinessException) {
            BusinessException businessException = (BusinessException) cause.getCause();
        }
        Enum<?> finalExceptionEnum = exceptionEnum;
        return new EventUserFeignClient() {
            @Override
            public HttpResult<List<EventDetailVO>> queryEventList(CsEventUserQueryParam csEventUserQueryParam) {
                log.error("{}异常，降级处理，异常为：{}","获取当天事件未读消息未读消息",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<Boolean> addUserEventList(List<CsEventUserPO> list) {
                log.error("{}异常，降级处理，异常为：{}","新增数据异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<Boolean> deleteByIds(List<String> eventList) {
                log.error("{}异常，降级处理，异常为：{}","根据id删除数据异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<String>> queryTempEvent(CsEventUserQueryParam param) {
                log.error("{}异常，降级处理，异常为：{}","查询暂态事件(未读)异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<CsEventPO>> queryTempEventDetail(CsEventUserQueryParam param) {
                log.error("{}异常，降级处理，异常为：{}","查询暂态事件详细信息(未读)异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<String>> queryTempHarmonic(CsEventUserQueryParam param) {
                log.error("{}异常，降级处理，异常为：{}","查询稳态事件(未读)异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<String>> queryAlarmEvent(CsEventUserQueryParam param) {
                log.error("{}异常，降级处理，异常为：{}","查询告警事件(未读)异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<String>> queryRunEvent(CsEventUserQueryParam param) {
                log.error("{}异常，降级处理，异常为：{}","查询运行事件(未读)异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }
        };
    }
}
