{% import "macros.txt.j2" as macros with context %}

╔═══════════════════════════╗
║ <header>{{ "{:^25}".format("Results") }}</header> ║
╚═══════════════════════════╝
{%- if flagged_messages | length > 0 %}
    {% set msg = flagged_messages[0] %}
{%- else %}
    {% set msg = unflagged_messages[0] %}
{%- endif %}
<key>File Name</key>: <value>{{msg.file_name}}</value>
{%- if msg.directory %}
<key>Directory</key>: <value>{{msg.directory}}</value>
{%- endif %}

<key>Total Rules</key>: <value>{{stats.total_rules}}</value>
<key>Total Queries</key>: <value>{{stats.total_queries}}</value>
{%- if stats.total_rules > 0 -%}
{# new line #}
<key>Flagged Rules</key>: <value>{{stats.flagged_rules}}</value>
{%- endif -%}
{# new line #}
{# new line #}

{%- if msg.flagged_rule_results|length > 0 -%}
{{ macros.flagged_rules(msg) }}
{%- endif -%}

{%- if msg.unflagged_rule_results|length > 0 %}
{# new line #}
<header>UNFLAGGED RULES</header>
{# new line #}
{%- set max_elements = 20 %}
{%- set elements_slice = msg.unflagged_rule_results[:max_elements if verbose < 1 else None] %}
{%- for rule in elements_slice %}
  - <not-detected><bold>{{ rule.name }}</bold></not-detected>
  {%- if verbose %}
    <key>Source:</key> {{ rule.source }}
    {# new line #}
  {%- endif %}
{%- endfor %}
{% if msg.unflagged_rule_results | length > max_elements and verbose < 1  -%}
{{ " " | indent(2) }} - <not-detected>And {{ msg.unflagged_rule_results | length - max_elements}} more. Run again with -v for full output.</not-detected>
{% endif -%}
{%- endif %}

{%- if msg.failed_rule_results|length > 0 %}
{{ macros.failed_rules(msg) }}
{%- endif %}

{%- if true -%}
{{ macros.query_results(msg) }}
{%- endif -%}
