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

import com.jay.monitor.data.core.enums.MsgTypeEnums;
import com.jay.monitor.data.core.model.serializable.URLDataDTO;
import com.jay.monitor.data.server.models.entity.JayMonitorUrl;
import com.jay.monitor.data.server.models.response.trace.URLTraceResponse;
import org.springframework.beans.BeanUtils;

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

public class MysqlURLSearchProcess extends AbstractMysqlSearchProcess<JayMonitorUrl, URLDataDTO, URLTraceResponse> {

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

    @Override
    public JayMonitorUrl builderQuery(URLDataDTO query) throws Exception {
        JayMonitorUrl jayMonitorUrl = new JayMonitorUrl();
        BeanUtils.copyProperties(query, jayMonitorUrl);
        return jayMonitorUrl;
    }

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