{% load idm_tags i18n %}
{% comment %}
Context variables:
    report - dictionary such as:
    {
        system: {
            'system_has_unknown_user': ['login1', 'login2'],
            'system_has_unknown_group': ['group1', 'group2'],
            'we_have_system_dont': {
                user_or_group1: [
                    inconsistency1, inconsistency2, inconsistency3
                ],
                user_or_group2: [
                    inconsistency3, inconsistency4, inconsistency5
                ]
            },
            'system_has_we_dont': {
                user_or_group1: [
                    inconsistency1, inconsistency2, inconsistency3
                ],
                user_or_group2: [
                    inconsistency3, inconsistency4, inconsistency5
                ]
            }
        },
    }
{% endcomment %}
{% stripbreaks %}

{% for system, inconsistencies in report.items %}
{% with system_name=system.get_name %}
{% blocktrans %}В системе {{ system_name }} есть расхождения{% endblocktrans %}:
    {% if inconsistencies.format == 'short' %}
    {% for type, info in inconsistencies.statistics.items %}
        {{ info.name }}: {{ info.count }}
    {% endfor %}
    {% else %}
    {% if inconsistencies.system_has_unknown_user %}
        {% line %}
        {% blocktrans %}В системе {{ system_name }} существуют сотрудники со следующими логинами,
        о которых не знает IDM:{% endblocktrans %}
        {% endline %}
        {% for inconsistency in inconsistencies.system_has_unknown_user %}{% line %}
            {{ inconsistency.as_report|safe }}{% if not forloop.last %},{% endif %}
        {% endline %}
        {% endfor %}
    {% endif %}

    {% if inconsistencies.system_has_unknown_group %}
        {% line %}
        {% blocktrans %}В системе {{ system_name }} существуют группы со следующими идентификаторами,
        о которых не знает IDM:{% endblocktrans %}
        {% endline %}
        {% for inconsistency in inconsistencies.system_has_unknown_group %}{% line %}
            {{ inconsistency.as_report|safe }}{% if not forloop.last %},{% endif %}
        {% endline %}
        {% endfor %}
    {% endif %}

    {% for subject, inconsistencies in inconsistencies.system_has_unknown_role.items %}
        {% line %}
        {% blocktrans with who=subject|who system_name=system_name %}
            {{ who }} имеет в системе {{ system_name }} роли,
            которые не соответствуют ни одному из узлов дерева ролей системы,
            известных IDM:
        {% endblocktrans %}
        {% endline %}
        {% for inconsistency in inconsistencies %}{% line %}
            {{ inconsistency.as_report|safe }}{% if not forloop.last %},{% endif %}
        {% endline %}
        {% endfor %}
    {% endfor %}

    {% for subject, inconsistencies in inconsistencies.system_has_we_dont.items %}
        {% line %}
        {% blocktrans with who=subject|who system_name=system_name%}
            {{ who }} имеет в системе {{ system_name }} роли, о которых не знает IDM:{% endblocktrans %}
        {% endline %}
        {% for inconsistency in inconsistencies %}{% line %}
            {{ inconsistency.as_report|safe }}{% if not forloop.last %},{% endif %}
        {% endline %}
        {% endfor %}
    {% endfor %}

    {% for subject, inconsistencies in inconsistencies.we_have_system_dont.items %}
        {% line %}
        {% blocktrans with who=subject|who system_name=system_name %}
            {{ who }} имеет в IDM роли, о которых не знает {{ system_name }}:
        {% endblocktrans %}
        {% endline %}
        {% for inconsistency in inconsistencies %}{% line %}
            {{ inconsistency.as_report|safe }}{% if not forloop.last %},{% endif %}
        {% endline %}
        {% endfor %}
    {% endfor %}
    {% endif %}
{% endwith %}
{% endfor %}
{% endstripbreaks %}