from itertools import chain as _chain


def calc_vector_conditions(messages, services, functions):
    mes = _chain(*messages)
    ser = list(_chain(*services))
    fun = list(_chain(*functions))
    conditions = []
    for idx, message in enumerate(mes):
        service = ser[idx]
        function = fun[idx]
        condition = '(.SYSLOG_IDENTIFIER == "' + service + '" && '
        if not function:
            condition += '.message == "' + message + '"'
        else:
            condition += function + '(to_string(.message) ?? "", "' + message + '")'
        condition += ')'
        if condition not in conditions:
            conditions.append(condition)
    return '!(' + ' || '.join(conditions) + ')'