package com.usky.demo.factory;

import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.exception.BusinessException;
import com.usky.common.core.exception.FeignBadRequestException;
import com.usky.demo.RemoteTsdbProxyService;
import com.usky.demo.domain.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

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


/**
 * 用户服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteTsdbProxyFallbackFactory implements FallbackFactory<RemoteTsdbProxyService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteTsdbProxyFallbackFactory.class);

    @Override
    public RemoteTsdbProxyService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteTsdbProxyService() {
//            @Override
//            public ApiResult<Void> sendDeviceData(DeviceDataWriteVO writeVO) {
//                throw new BusinessException(throwable.getMessage());
//            }

//            @Override
//            public List<LastInnerResultVO> last(LastInnerQueryVO requestVO)
//            {
//                throw new BusinessException("设备实时数据查询:" + throwable.getMessage());
//            }

            @Override
            public ApiResult<List<Map<String, Object>>> getAllDeviceRealTime()
            {
                throw new BusinessException("查询influxdb所有表实时数据:" + throwable.getMessage());
            }

//            @Override
//            public LastResultVO queryLastDeviceData(String deviceUUId)
//            {
//                throw new BusinessException("单个设备实时数据查询:" + throwable.getMessage());
//            }

            @Override
            public ApiResult<List<LastInnerResultVO>> queryLastDeviceData(LastInnerQueryVO requestVO)
            {
                throw new BusinessException("批量设备实时数据查询:" + throwable.getMessage());
            }

//            @Override
//            public HistoryResultVO queryHistoryDeviceData(String deviceUUId,
//                                                                     String startTime,
//                                                                     String endTime)
//            {
//                throw new BusinessException("单个设备历史数据查询:" + throwable.getMessage());
//            }

            @Override
            public ApiResult<List<HistorysInnerResultVO>> queryHistoryDeviceData(HistorysInnerRequestVO requestVO)
            {
                throw new BusinessException("批量设备历史数据查询:" + throwable.getMessage());
            }

            @Override
            public Void createSuperTableAndColumn(SuperTableDTO superTableDTO)
            {
                throw new BusinessException("创建超级表和列:" + throwable.getMessage());
            }

            @Override
            public Void addSuperTableColumn(SuperTableDTO superTableDTO)
            {
                throw new BusinessException("添加超级表列:" + throwable.getMessage());
            }

            @Override
            public Void dropSuperTableColumn(SuperTableDTO superTableDTO)
            {
                throw new BusinessException("删除超级表列:" + throwable.getMessage());
            }

            @Override
            public EnergyItemSumResultVO sumEnergyItem(EnergyItemSumQueryVO requestVO)
            {
                throw new BusinessException("能耗分项汇总查询:" + throwable.getMessage());
            }

            @Override
            public EnergyItemTrendResultVO sumEnergyItemTrend(EnergyItemTrendQueryVO requestVO)
            {
                throw new BusinessException("能耗分项趋势查询:" + throwable.getMessage());
            }

            @Override
            public ApiResult<DeviceCsvImportResultVO> importDeviceCsv(String deviceUuid, org.springframework.web.multipart.MultipartFile file)
            {
                log.error("设备时序 CSV 导入失败: {}", throwable.getMessage());
                return ApiResult.error("设备时序 CSV 导入:" + throwable.getMessage());
            }
        };
    }
}
