package com.arms.egovframework.javaservice.esframework.repository.common;

import com.arms.egovframework.javaservice.esframework.model.dto.esquery.CompositeGroupDTO;
import com.arms.egovframework.javaservice.esframework.model.dto.esquery.SearchDocDTO;
import com.arms.egovframework.javaservice.esframework.model.vo.CatIndexVO;
import com.arms.egovframework.javaservice.esframework.model.vo.CompositeAggregationResultWrapper;
import com.arms.egovframework.javaservice.esframework.model.vo.DocumentAggregations;
import com.arms.egovframework.javaservice.esframework.model.vo.DocumentResultWrapper;

import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.repository.NoRepositoryBean;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

@NoRepositoryBean
public interface EsCommonRepository<T, U extends Serializable> extends ElasticsearchRepository<T, U> {

	DocumentAggregations aggregateDocs(Query query);

	CompositeAggregationResultWrapper<T> compositeHits(Query query);

	CompositeAggregationResultWrapper<T> compositeAllHits(CompositeGroupDTO compositeGroupDTO, Function<CompositeGroupDTO, Query> function);

	DocumentResultWrapper<T> findAllHits();

	DocumentResultWrapper<T> findRecentAllHits();

	DocumentResultWrapper<T> findRecentHits(Query query);

	DocumentResultWrapper<T> findHits(Query query);

	<S extends T> S  save(S entity);

	<S extends T> S  modifyWithIndexName(S entity,String indexName);

	<S extends T> S saveEmpty(S entity);

	<S extends T> Iterable<S> saveAll(Iterable<S> entities);

	List<T> findDocsByScrollApi(Query query);

	String indexAliasName();

	String deleteDocByEntity(T t);

	List<T> findRecentDocsByScrollApi(Query query);

	List<T> findAllDocsBySearchAfter(SearchDocDTO searchDocDTO, Function<SearchDocDTO, Query> function);

	List<T> findAllRecentDocsBySearchAfter(SearchDocDTO searchDocDTO, Function<SearchDocDTO, Query> function);

	T findRecentDocByRecentId(U u);

	U deleteRecentDocById(U u);

	DocumentResultWrapper<T> findRecentDocById(U u);

	T findDocById(U u);

	void merge(int day);

	void reindex(Map<String, List<String>> indexNameGroupByMonth);

	void deleteIndex(Map<String, List<String>> indexNameGroupByMonth);

	void deleteIndex(int day);

	List<CatIndexVO> catIndexVOList();

	Long indexCount();

}
