package com.muyu.common.iotdb.service;

import com.muyu.common.iotdb.domain.dto.IotDbRecordAble;
import com.muyu.common.iotdb.domain.dto.MeasurementSchemaValuesDTO;
import org.apache.iotdb.common.rpc.thrift.TAggregationType;
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.write.record.Tablet;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;

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

/**
 * @Author WangXin
 * @Data 2024/9/28
 * @Description IotDBServiceImpl业务层
 * @Version 1.0.0
 */
public interface IotDBService {

    void insertTablet(Tablet tablet);

    void insertTablets(Map<String, Tablet> tablets);

    void insertStringRecord(String deviceId, Long time, List<String> measurements, List<String> values);

    void insertRecord(String deviceId, Long time, List<String> measurements, List<TSDataType> types, List<Object> values);

    void insertStringRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList);

    void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList);

    void insertStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList);

    void insertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList);

    void deleteData(String path, Long endTime);

    void deleteData(List<String> paths, Long endTime);

    SessionDataSet executeRawDataQuery(List<String> paths, Long startTime, Long endTime, Long timeOut);

    <T> List<T> executeRawDataQuery(List<String> paths, Long startTime, Long endTime, Long timeOut, Class<? extends IotDbRecordAble> clazz);

    SessionDataSet executeLastDataQuery(List<String> paths, Long lastTime);

    <T> List<T> executeLastDataQuery(List<String> paths, Long lastTime, Class<? extends IotDbRecordAble> clazz);

    SessionDataSet executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes);

    <T> List<T> executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes, Class<? extends IotDbRecordAble> clazz);

    SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations);

    SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, Long startTime, Long endTime);

    SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, Long startTime, Long endTime, Long interval);

    SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, Long startTime, Long endTime, Long interval, Long slidingStep);

    SessionDataSet executeQueryStatement(String sql);


    /**
     * SQL非查询
     *
     * @param sql
     */
    void executeNonQueryStatement(String sql);

    /**
     * 封装处理数据
     *
     * @param sessionDataSet
     * @param titleList
     */
    List<Map<String, Object>> packagingMapData(SessionDataSet sessionDataSet, List<String> columnNames);

    /**
     * 封装处理数据（不支持聚合查询）
     *
     * @param sessionDataSet 查询返回的结果集
     * @param titleList      查询返回的结果集内的字段名
     * @param clazz          返回数据对应的对象（对象属性必须与字段名对应）
     * @param <T>
     * @return
     */
    <T> List<T> packagingObjectData(SessionDataSet sessionDataSet, List<String> titleList, Class<? extends IotDbRecordAble>  clazz);

    /**
     * 根据对象构建MeasurementSchemas
     *
     * @param object 对象
     * @return
     */
    List<MeasurementSchema> buildMeasurementSchemas(Object object);
    /**
     * 根据对象构建MeasurementSchemaValuesDTO
     *
     * @param object 对象
     * @return
     */
    MeasurementSchemaValuesDTO buildMeasurementSchemasAndValues(Object object);
}
