package com.jay.monitor.data.server.store.es;

import com.jay.monitor.data.core.enums.MsgTypeEnums;
import com.jay.monitor.data.server.models.entity.es.JayMonitorSQLIndex;
import com.jay.monitor.data.server.models.request.trace.SQLRequest;
import com.jay.monitor.data.server.models.response.trace.SQLTraceResponse;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class SQLElasticSearchProcess
    extends AbstractTraceElasticSearch<SQLRequest, SQLTraceResponse, JayMonitorSQLIndex> {

    @Override
    public Class getIndexClass() {
        return JayMonitorSQLIndex.class;
    }

    @Override
    public MsgTypeEnums msgTypeEnums() {
        return MsgTypeEnums.SQL;
    }

    @Override
    public List<SQLTraceResponse> builderResponseList(List<JayMonitorSQLIndex> list) {
        List<SQLTraceResponse> sqlTraceResponses = new ArrayList<>();
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                JayMonitorSQLIndex jayMonitorSQLIndex = list.get(i);
                SQLTraceResponse sqlTraceResponse = new SQLTraceResponse();
                BeanUtils.copyProperties(jayMonitorSQLIndex, sqlTraceResponse);
                sqlTraceResponses.add(sqlTraceResponse);
            }
        }
        return sqlTraceResponses;
    }
}
