package com.hw.tdengine.api;

import com.hw.common.core.constant.SecurityConstants;
import com.hw.common.core.constant.ServiceNameConstants;
import com.hw.common.core.domain.R;
import com.hw.common.core.validated.tdengine.AddTdSTableColumn;
import com.hw.common.core.validated.tdengine.InsertTdTable;
import com.hw.tdengine.api.domain.*;
import com.hw.tdengine.api.domain.ems.TdSuperTableEmsSelectVo;
import com.hw.tdengine.api.factory.RemoteTdEngineFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

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

@FeignClient(contextId = "remoteTdEngineService", value = ServiceNameConstants.TDENGINE_SERVICE, fallbackFactory = RemoteTdEngineFallbackFactory.class)
public interface RemoteTdEngineService {

    @PostMapping("/tdengine/createDatabase")
    R<?> createDataBase(@RequestBody String databaseName, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/createSuperTable")
    R<?> createSuperTable(@Validated @RequestBody TdSuperTableVo tdSuperTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/createTable")
    R<?> createTable(@Validated @RequestBody TdTableVo tdTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/addSuperTableColumn")
    R<?> addSuperTableColumn(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/modifySuperTableColumn")
    R<?> modifySuperTableColumn(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/dropSuperTableColumn")
    R<?> dropColumnForSuperTable(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/alterTableTag")
    public R<?> alterTableTag(@Validated @RequestBody AlterTagVo alterTagVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/insertTable")
    R<?> insertTable(@Validated(InsertTdTable.class) @RequestBody TdTableVo tdTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/getLatestData")
    R<?> getLatestData(@Validated @RequestBody TdSelectDto tdSelectDto, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/getLatestDataByTags")
    R<List<Map<String, Object>>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSuperTableSelectVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/getHistoryData")
    R<TdReturnDataVo> getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/getCountOfHistoryData")
    R<?> getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/getOnlineDevicesGroupByDay")
    R<?> getOnlineDevicesGroupByDay(@Validated @RequestBody DeviceStatus queryDeviceStatus, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/getLastOnlineDevices")
    R<?> getLastOnlineDevices(@Validated @RequestBody DeviceStatus queryDeviceStatus, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/getDeviceStatusList")
    R<List<Map<String, Object>>> getDeviceStatusList(@Validated @RequestBody DeviceStatus queryDeviceStatus, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/getSuperTableHistoryData")
    R<TdReturnDataVo> getSuperTableHistoryData(@Validated @RequestBody TdSuperTableEmsSelectVo tdSuperTableEmsSelectVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/tdengine/alterTableTags")
    public R<?> alterTableTags(@Validated @RequestBody List<AlterTagVo> alterTagVos, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

}
