package com.arms.egovframework.javaservice.esframework.esquery.sort;

import com.arms.egovframework.javaservice.esframework.esquery.EsQuery;
import com.arms.egovframework.javaservice.esframework.model.dto.esquery.SortDTO;
import org.opensearch.search.sort.FieldSortBuilder;
import org.opensearch.search.sort.SortBuilders;
import org.opensearch.search.sort.SortOrder;

import java.util.List;
import java.util.stream.Collectors;

public class EsSortQuery extends EsQuery {

	private final List<FieldSortBuilder> fieldSortBuilderList;

	public EsSortQuery(List<SortDTO> sortDTOS){
		this.fieldSortBuilderList = sortDTOS.stream()
			.map(sortDTO -> SortBuilders.fieldSort(sortDTO.getField()).order(SortOrder.fromString(sortDTO.getSortType())))
			.collect(Collectors.toList());
	}

	public List<FieldSortBuilder> sortBy() {
		return this.fieldSortBuilderList;
	}

}
