class UserMessageArchivePreferencesElement {

    static XMLElement toXml(String namespace, UserMessageArchivePreferences preferences) {
        List<XMLFragment> alwaysJids = preferences.getAlwaysArchivedToOrFromJids().stream()
                .map(entity -> new XMLElement(null, "jid", null, Collections.emptyList(),
                        Collections.singletonList(new XMLText(entity.getFullQualifiedName()))))
                .collect(Collectors.toList());
        XMLElement alwaysElement = new XMLElement(null, "always", null, Collections.emptyList(), alwaysJids);

        List<XMLFragment> neverJids = preferences.getNeverArchivedToOrFromJids().stream()
                .map(entity -> new XMLElement(null, "jid", null, Collections.emptyList(),
                        Collections.singletonList(new XMLText(entity.getFullQualifiedName()))))
                .collect(Collectors.toList());
        XMLElement neverElement = new XMLElement(null, "never", null, Collections.emptyList(), neverJids);

        List<XMLFragment> prefsFragments = new ArrayList<>();
        prefsFragments.add(alwaysElement);
        prefsFragments.add(neverElement);

        Attribute defaultBehaviour = new Attribute("default", preferences.getDefaultBehaviour().name().toLowerCase());
        return new XMLElement(namespace, NAME, null, Collections.singletonList(defaultBehaviour), prefsFragments);
    }

    private  UserMessageArchivePreferencesElement();

}