package com.njcn.csdevice.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.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.pojo.dto.CsLineDTO;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.LineDetailDataVO;
import com.njcn.device.biz.pojo.po.Overlimit;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

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

/**
 * @author xy
 */
@Slf4j
@Component
public class CsLineClientFallbackFactory implements FallbackFactory<CsLineFeignClient> {
    @Override
    public CsLineFeignClient create(Throwable cause) {
        //判断抛出异常是否为解码器抛出的业务异常
        Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
        if (cause.getCause() instanceof BusinessException) {
            BusinessException businessException = (BusinessException) cause.getCause();
        }
        Enum<?> finalExceptionEnum = exceptionEnum;
        return new CsLineFeignClient() {

            @Override
            public HttpResult<List<CsLinePO>> queryLineById(List<String> ids) {
                log.error("{}异常，降级处理，异常为：{}","查询监测点详情异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<CsLinePO>> queryLineByDevId(String id) {
                log.error("{}异常，降级处理，异常为：{}","查询监测点详情异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);            }

            @Override
            public HttpResult<String> addLineList(List<CsLinePO> list) {
                log.error("{}异常，降级处理，异常为：{}","批量新增加监测点",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<CsLinePO>> findByNdid(String id) {
                log.error("{}异常，降级处理，异常为：{}","根据ndid查询监测点",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<Map<String,String>> getCustomDetailByLineId(@RequestParam("id") String id) {
                log.error("{}异常，降级处理，异常为：{}","根据id查询监测点",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<String> getPositionById(String id) {
                log.error("{}异常，降级处理，异常为：{}","通过id查询监测点位置",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<String> updateLine(CsLineParam csLineParam) {
                log.error("{}异常，降级处理，异常为：{}","更新监测点信息",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<Boolean> updateIds(CsLineParam csLineParam) {
                log.error("{}异常，降级处理，异常为：{}","修改监测点模板id和数据集id",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<CsLinePO> getById(String lineId) {
                log.error("{}异常，降级处理，异常为：{}","根据监测点id获取监测点详情",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<CsLinePO>> getLinesByDevList(List<String> ids) {
                log.error("{}异常，降级处理，异常为：{}","根据装置id集合获取监测点id集合",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<String> updateDataByList(List<String> list, String id, String setId) {
                log.error("{}异常，降级处理，异常为：{}","根据装置集合修改监测点信息",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<String>> getAllLine() {
                log.error("{}异常，降级处理，异常为：{}","获取所有监测点id",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<CsLineDTO>> getAllLineDetail() {
                log.error("{}异常，降级处理，异常为：{}","获取系统中所有监测点id详情异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<Overlimit>> getOverLimitData(List<String> ids) {
                log.error("{}异常，降级处理，异常为：{}","根据监测点id集合获取国标限值异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<CsEquipmentDeliveryPO>> getDevBySensitiveUser(List<String> list) {
                log.error("{}异常，降级处理，异常为：{}","根据敏感用户查询监测点异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<CsLinePO>> getLineByName(String lineName) {
                log.error("{}异常，降级处理，异常为：{}","根据名称查询监测点异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }
            @Override
            public HttpResult<List<CsLinePO>> list(CsLinePO param) {
                log.error("{}异常，降级处理，异常为：{}","查询监测点列表异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<LineDetailDataVO> getLineDetailData(@RequestParam("id") String id) {
                log.error("{}异常，降级处理，异常为：{}","查询监测点详情异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<CsLinePO>> getSimpleLine() {
                log.error("{}异常，降级处理，异常为：{}","查询登录用户拥有的监测点台账",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }
        };
    }
}
