class HibernateSimpleQueryUtils {

    public static String makeQueryPrefixAndFuzzy(@NonNull String simpleQuery) {
        var trimmedSimpleQuery = simpleQuery.trim();
        var replaceableTermIndexPairs = getReplaceableTermsOfQuery(trimmedSimpleQuery);

        if(replaceableTermIndexPairs.isEmpty()) {
            return trimmedSimpleQuery;
        }

        var fuzzyAndPrefixQuery = trimmedSimpleQuery;
        var addedOffsetByReplacingTerms = 0;

        for(var pair : replaceableTermIndexPairs) {
            var termStartIndex = pair.getFirst() + addedOffsetByReplacingTerms;
            var termEndIndex = pair.getSecond() + addedOffsetByReplacingTerms;
            var termStartEndIndexPair = Pair.of(termStartIndex, termEndIndex);

            var preReplacementQueryLength = fuzzyAndPrefixQuery.length();
            fuzzyAndPrefixQuery = replaceTermWithFuzzyAndPrefixDisjunction(termStartEndIndexPair, fuzzyAndPrefixQuery);
            var postReplacementQueryLength = fuzzyAndPrefixQuery.length();

            addedOffsetByReplacingTerms += postReplacementQueryLength - preReplacementQueryLength;
        }

        return fuzzyAndPrefixQuery;
    }

}