package com.arms.egovframework.javaservice.esframework.factory;

import com.arms.egovframework.javaservice.esframework.factory.builder.AbstractQueryBuilder;
import com.arms.egovframework.javaservice.esframework.factory.creator.CompositeAggregationQueryCreator;
import com.arms.egovframework.javaservice.esframework.model.dto.esquery.CompositeGroupDTO;
import com.arms.egovframework.javaservice.esframework.model.entity.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.opensearch.data.client.orhlc.NativeSearchQuery;

@Setter
@Getter
public class CompositeAggregationQueryFactory implements AbstractQueryBuilder<NativeSearchQuery> {

	private final AbstractQueryBuilder<NativeSearchQuery> abstractQueryBuilder;

	private CompositeAggregationQueryFactory(AbstractQueryBuilder<NativeSearchQuery> abstractQueryBuilder) {
		this.abstractQueryBuilder = abstractQueryBuilder;
	}

	public static AbstractQueryBuilder<NativeSearchQuery> composite(CompositeGroupDTO compositeGroupDTO) {
		return new CompositeAggregationQueryFactory(
			CompositeAggregationQueryCreator.of(compositeGroupDTO, compositeGroupDTO.getEsQuery())
		);
	}

	@Override
	public NativeSearchQuery create() {
		return abstractQueryBuilder.create();
	}

	@Override
	public NativeSearchQuery createForRecentTrue(Class<? extends BaseEntity> entityClass) {
		return abstractQueryBuilder.createForRecentTrue(entityClass);
	}

}
