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

import com.jay.monitor.data.core.model.response.PageResponseModel;
import com.jay.monitor.data.server.enums.StoreType;
import com.jay.monitor.data.server.store.StoreDataManager;
import com.jay.monitor.data.server.store.TraceSearchProcess;
import com.jay.monitor.data.server.utils.JayDataUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public abstract class AbstractMysqlSearchProcess<E, Q, R> extends TraceSearchProcess<Q, R> {

    @Autowired
    private StoreDataManager storeDataManager;

    public abstract List<R> builderResponse(List<E> query) throws Exception;

    public abstract E builderQuery(Q query) throws Exception;

    @Override
    public PageResponseModel<R> searchDataByList(String date, Integer pageNo, Integer pageSize, Q query)
        throws Exception {
        E builderQuery = builderQuery(query);
        List<E> searchList = storeDataManager.searchDataByList(msgTypeEnums(), date, pageSize, builderQuery);
        List<R> responseList = builderResponse(searchList);
        PageResponseModel<R> jayMonitorMqPageResponseModel =
            JayDataUtils.builderPageResponseModel(pageNo, pageSize, responseList.size(), responseList);
        return jayMonitorMqPageResponseModel;
    }

    @Override
    public StoreType storeType() {
        return StoreType.MYSQL;
    }
}
