package com.hw.tdengine.api.factory;

import com.alibaba.fastjson2.JSONObject;
import com.hw.common.core.domain.R;
import com.hw.tdengine.api.RemoteTdEngineService;
import com.hw.tdengine.api.domain.*;
import com.hw.tdengine.api.domain.ems.TdSuperTableEmsSelectVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

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

/**
 * @Description: TDengine服务降级处理
 * @ClassName: RemoteTdEngineFallbackFactory
 * @Author : xins
 * @Date :2023-09-01  14:14
 * @Version :1.0
 */
@Component
public class RemoteTdEngineFallbackFactory implements FallbackFactory<RemoteTdEngineService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteTdEngineFallbackFactory.class);

    @Override
    public RemoteTdEngineService create(Throwable throwable) {
        return new RemoteTdEngineService() {
            @Override
            public R<?> createDataBase(String databaseName, String source) {
                return R.fail("创建数据库失败:" + throwable.getMessage());
            }

            @Override
            public R<?> createSuperTable(TdSuperTableVo tdSuperTableVo, String source) {
                return R.fail("创建超级表失败:" + throwable.getMessage());
            }

            @Override
            public R<?> createTable(TdTableVo tdTableVo, String source) {
                return R.fail("创建子表失败:" + throwable.getMessage());
            }

            @Override
            public R<?> addSuperTableColumn(TdSuperTableVo tdSuperTableVo, String source) {
                return R.fail("添加超级表Column失败:" + throwable.getMessage());
            }

            @Override
            public R<?> modifySuperTableColumn(TdSuperTableVo tdSuperTableVo, String source) {
                return R.fail("修改超级表Column失败:" + throwable.getMessage());
            }

            @Override
            public R<?> dropColumnForSuperTable(TdSuperTableVo tdSuperTableVo, String source) {
                return R.fail("删除超级表Column失败:" + throwable.getMessage());
            }

            @Override
            public R<?> alterTableTag(AlterTagVo alterTagVo, String source) {
                return R.fail("修改子表tag值失败:" + throwable.getMessage());
            }

            @Override
            public R<?> insertTable(TdTableVo tdTableVo, String source) {
                return R.fail("插入数据失败:" + throwable.getMessage());
            }

            @Override
            public R<?> getLatestData(TdSelectDto tdSelectDto, String source) {
                return R.fail("获取子表最新数据失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Map<String, Object>>> getLatestDataByTags(TdSuperTableSelectVo tdSuperTableSelectVo, String source) {
                return R.fail("根据tags获取超级表最新数据失败:" + throwable.getMessage());
            }

            @Override
            public R<TdReturnDataVo> getHistoryData(TdHistorySelectDto tdHistorySelectDto, String source) {
                return R.fail("获取历史数据失败:" + throwable.getMessage());
            }

            @Override
            public R<?> getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto, String source) {
                return R.fail("获取历史数据数量失败:" + throwable.getMessage());
            }

            @Override
            public R<?> getOnlineDevicesGroupByDay(DeviceStatus queryDeviceStatus, String source) {
                return R.fail("获取设备状态失败:" + throwable.getMessage());
            }

            @Override
            public R<?> getLastOnlineDevices(DeviceStatus queryDeviceStatus, String source) {
                return R.fail("获取最近设备状态失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Map<String, Object>>> getDeviceStatusList(DeviceStatus queryDeviceStatus, String source) {
                return R.fail("获取设备状态信息失败:" + throwable.getMessage());
            }

            @Override
            public R<TdReturnDataVo> getSuperTableHistoryData(TdSuperTableEmsSelectVo tdSuperTableEmsSelectVo, String source) {
                return R.fail("获取超级表历史数据失败:" + throwable.getMessage());
            }

            @Override
            public R<?> alterTableTags(List<AlterTagVo> alterTagVos, String source) {
                return R.fail("批量修改子表tag值失败:" + throwable.getMessage());
            }

        };
    }
}
