class Operators {

    private static void writeFieldInArrayCheckCondition(
            final QueryStatement query,
            final QueryWriterResolver resolver,
            final FieldPath contextFieldPath,
            final Object queryParameter
    ) throws QueryBuildException {

        if (contextFieldPath == null) {
            throw new QueryBuildException("Operator \"$in\" not allowed outside of field context");
        }

        if (!(queryParameter instanceof List)) {
            throw new QueryBuildException("\"$in\" operator must be applied only to JSON array");
        }

        List paramAsList = (List) queryParameter;
        Writer writer = query.getBodyWriter();

        try {
            if (paramAsList.size() == 0) {
                writer.write("(FALSE)");
                return;
            }

            writer.write(String.format("((%s)in(", contextFieldPath.toSQL()));

            for (int i = paramAsList.size(); i > 0; --i) {
                writer.write(String.format("to_json(?)::jsonb%s", (i == 1) ? "" : ","));
            }

            writer.write("))");

            query.pushParameterSetter((statement, index) -> {
                for (Object obj : paramAsList) {
                    statement.setObject(index++, obj);
                }
                return index;
            });

        } catch (IOException e) {
            throw new QueryBuildException("Query search conditions write failed because of exception", e);
        }
    }

    private  Operators();

}