class urn_perun_group_resource_attribute_def_def_o365EmailAddresses_mu extends GroupResourceAttributesModuleAbstract implements GroupResourceAttributesModuleImplApi {

	@Override
	public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
		List<String> emails = attribute.valueAsList();

		if (emails == null) emails = new ArrayList<>();
		//at least one value if adName is set
		AttributesManagerBl am = sess.getPerunBl().getAttributesManagerBl();
		try {
			if (emails.isEmpty()) {
				Attribute adName = am.getAttribute(sess, resource, group, ADNAME_ATTRIBUTE);
				if (adName.getValue() != null) {
					throw new WrongReferenceAttributeValueException(attribute, adName, resource, group, resource, group, "at least one email must be defined");
				}

				return;
			}
		} catch (AttributeNotExistsException | GroupResourceMismatchException e) {
			throw new InternalErrorException(e.getMessage(), e);
		}

		//check for duplicities among all members and groups
		AttributesManagerBl attributesManagerBl = sess.getPerunBl().getAttributesManagerBl();
		Set<Pair<Integer, Integer>> groupResourcePairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, attribute);
		groupResourcePairs.remove(new Pair<>(group.getId(), resource.getId()));
		if (!groupResourcePairs.isEmpty()) {
			throw new WrongReferenceAttributeValueException(attribute, attribute, group, resource, "some of the email addresses are already assigned to the following group_resource pairs: " + groupResourcePairs);
		}
		Attribute memberO365EmailAddresses = new Attribute(new urn_perun_member_attribute_def_def_o365EmailAddresses_mu().getAttributeDefinition());
		memberO365EmailAddresses.setValue(emails);
		Set<Pair<Integer, Integer>> memberPairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, memberO365EmailAddresses);
		if (!memberPairs.isEmpty()) {
			throw new WrongReferenceAttributeValueException(attribute, memberO365EmailAddresses, group, resource, "member " + BeansUtils.getSingleId(memberPairs) + " ");
		}
	}

}