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

import com.jay.monitor.data.core.enums.MsgTypeEnums;
import com.jay.monitor.data.server.models.entity.JayMonitorSql;
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 MysqlSQLSearchProcess extends AbstractMysqlSearchProcess<JayMonitorSql, SQLRequest, SQLTraceResponse> {

    @Override
    public List<SQLTraceResponse> builderResponse(List<JayMonitorSql> resultList) throws Exception {
        List<SQLTraceResponse> responseList = new ArrayList<>();
        for (int i = 0; i < resultList.size(); i++) {
            SQLTraceResponse sqlTraceResponse = new SQLTraceResponse();
            BeanUtils.copyProperties(resultList.get(i), sqlTraceResponse);
            responseList.add(sqlTraceResponse);
        }
        return responseList;
    }

    @Override
    public JayMonitorSql builderQuery(SQLRequest query) throws Exception {
        JayMonitorSql jayMonitorSql = new JayMonitorSql();
        BeanUtils.copyProperties(query, jayMonitorSql);
        return jayMonitorSql;
    }

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