class urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu extends GroupAttributesModuleAbstract implements GroupAttributesModuleImplApi {

	@Override
	public void checkAttributeSemantics(PerunSessionImpl sess, Group group, 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, group, ADNAME_ATTRIBUTE);
				if (adName.getValue() != null) {
					throw new WrongReferenceAttributeValueException(attribute, adName, group, null, group, null, "at least one email must be defined");
				}

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

		//No need to check duplicities among other groups (attribute is unique)
		//check for duplicities among members attributes and this one
		try {
			AttributesManagerBl attributesManagerBl = sess.getPerunBl().getAttributesManagerBl();
			Attribute memberO365EmailAddresses = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, MEMBER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE));
			memberO365EmailAddresses.setValue(emails);
			Set<Pair<Integer, Integer>> memberPairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, memberO365EmailAddresses);
			if (!memberPairs.isEmpty()) {
				throw new WrongReferenceAttributeValueException(attribute, memberO365EmailAddresses, group, null, "member " + BeansUtils.getSingleId(memberPairs) + " ");
			}
		} catch(AttributeNotExistsException ex) {
			//If attribute not exists, we can log it and skip it, because there are no duplicates in not existing attributes
			log.debug("Attribute {} not exists to check duplicities in it while checkAttributeSemantics for {}.", MEMBER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE, attribute);
		}
	}

}