class InviteUserServiceImpl extends BaseTransactionalService implements InviteUserService {

    @Override
    @Transactional
    public ServiceResult<Void> saveUserInvite(UserResource invitedUser, Role role) {
        if (StringUtils.isEmpty(invitedUser.getEmail()) || StringUtils.isEmpty(invitedUser.getFirstName())
                || StringUtils.isEmpty(invitedUser.getLastName()) || role == null){
            return serviceFailure(USER_ROLE_INVITE_INVALID);
        }

        if (externalRolesToInvite().contains(role)) {
            return validateExternalUserEmailDomain(invitedUser.getEmail(), role)
                    .andOnSuccess(() -> validateAndSaveInvite(invitedUser, role))
                    .andOnSuccess(this::inviteExternalUser);
        } else if (internalRoles().contains(role)) {
            return validateInternalUserEmailDomain(invitedUser.getEmail())
                    .andOnSuccess(() -> validateAndSaveInvite(invitedUser, role))
                    .andOnSuccess(this::inviteInternalUser);
        } else {
            return serviceFailure(NOT_AN_INTERNAL_USER_ROLE);
        }
    }

}