package li.strolch.search;

import static li.strolch.model.StrolchModelConstants.BAG_PARAMETERS;
import static li.strolch.model.StrolchModelConstants.BAG_RELATIONS;

import java.util.function.Supplier;

import li.strolch.model.StrolchRootElement;
import li.strolch.persistence.api.StrolchTransaction;

/**
 * Declares specific search expressions, i.e. extracting the relevant data for a where clause
 */
public interface SearchExpressions {

	default <T extends StrolchRootElement> SearchExpression<T> not(SearchExpression<T> expression) {
		return element -> !expression.matches(element);
	}

	default <T extends StrolchRootElement> SearchExpression<T> predicate(Supplier<Boolean> predicate) {
		return ExpressionsSupport.predicate(predicate);
	}

	default ExpressionBuilder id() {
		return ExpressionsSupport.id();
	}

	default <T extends StrolchRootElement> SearchExpression<T> id(SearchPredicate predicate) {
		return ExpressionsSupport.id(predicate);
	}

	default ExpressionBuilder name() {
		return ExpressionsSupport.name();
	}

	default <T extends StrolchRootElement> SearchExpression<T> name(SearchPredicate predicate) {
		return ExpressionsSupport.name(predicate);
	}

	default ExpressionBuilder date() {
		return ExpressionsSupport.date();
	}

	default <T extends StrolchRootElement> SearchExpression<T> date(SearchPredicate predicate) {
		return ExpressionsSupport.date(predicate);
	}

	default ExpressionBuilder state() {
		return ExpressionsSupport.state();
	}

	default <T extends StrolchRootElement> SearchExpression<T> state(SearchPredicate predicate) {
		return ExpressionsSupport.state(predicate);
	}

	default ExpressionBuilder param(String paramId) {
		return ExpressionsSupport.param(BAG_PARAMETERS, paramId);
	}

	default ExpressionBuilder relation(String paramId) {
		return ExpressionsSupport.param(BAG_RELATIONS, paramId);
	}

	default ExpressionBuilder param(String bagId, String paramId) {
		return ExpressionsSupport.param(bagId, paramId);
	}

	default <T extends StrolchRootElement> SearchExpression<T> param(String bagId, String paramId,
			SearchPredicate predicate) {
		return ExpressionsSupport.param(bagId, paramId, predicate);
	}

	default <T extends StrolchRootElement> SearchExpression<T> paramNull(String bagId, String paramId) {
		return ExpressionsSupport.paramNull(bagId, paramId);
	}

	default ExpressionBuilder relationName(StrolchTransaction tx, String paramId) {
		return ExpressionsSupport.relationName(tx, paramId);
	}

	default <T extends StrolchRootElement> SearchExpression<T> relationName(StrolchTransaction tx,
			String relationParamId, SearchPredicate predicate) {
		return ExpressionsSupport.relationName(tx, relationParamId, predicate);
	}

	default ExpressionBuilder relationParam(StrolchTransaction tx, String relationParamId, String bagId,
			String paramId) {
		return ExpressionsSupport.relationParam(tx, relationParamId, bagId, paramId);
	}

	default <T extends StrolchRootElement> SearchExpression<T> relationParam(StrolchTransaction tx,
			String relationParamId, String bagId, String paramId, SearchPredicate predicate) {
		return ExpressionsSupport.relationParam(tx, relationParamId, bagId, paramId, predicate);
	}
}

@@ -2043,122 +2043,464 @@
 ing 
-bagId, String paramId,%0A%09%09%09SearchPredicate predicate) %7B%0A%09%09return ExpressionsSupport.param(bagId, paramId, predicate
+paramId, SearchPredicate predicate) %7B%0A%09%09return ExpressionsSupport.param(BAG_PARAMETERS, paramId, predicate);%0A%09%7D%0A%0A%09default %3CT extends StrolchRootElement%3E SearchExpression%3CT%3E param(String bagId, String paramId,%0A%09%09%09SearchPredicate predicate) %7B%0A%09%09return ExpressionsSupport.param(bagId, paramId, predicate);%0A%09%7D%0A%0A%09default %3CT extends StrolchRootElement%3E SearchExpression%3CT%3E paramNull(String paramId) %7B%0A%09%09return ExpressionsSupport.paramNull(BAG_PARAMETERS, paramId
 );%0A%09
@@ -3132,113 +3132,585 @@
 ing 
-bagId,%0A%09%09%09String paramId) %7B%0A%09%09return ExpressionsSupport.relationParam(tx, relationParamId, bagId, paramId
+paramId) %7B%0A%09%09return ExpressionsSupport.relationParam(tx, relationParamId, BAG_PARAMETERS, paramId);%0A%09%7D%0A%0A%09default ExpressionBuilder relationParam(StrolchTransaction tx, String relationParamId, String bagId,%0A%09%09%09String paramId) %7B%0A%09%09return ExpressionsSupport.relationParam(tx, relationParamId, bagId, paramId);%0A%09%7D%0A%0A%09default %3CT extends StrolchRootElement%3E SearchExpression%3CT%3E relationParam(StrolchTransaction tx,%0A%09%09%09String relationParamId, String paramId, SearchPredicate predicate) %7B%0A%09%09return ExpressionsSupport.relationParam(tx, relationParamId, BAG_PARAMETERS, paramId, predicate
 );%0A%09

Add non-bagId overrides in SearchExpressions