class OrganizationNotificationEmailSender implements EventSubscriber<OrganizationEvent> {

  @Override
  public void onEvent(OrganizationEvent event) {
    try {
      if (event.getInitiator() != null) {
        if (event.getOrganization().getParent() == null) {
          try {
            userManager.getByName(event.getOrganization().getName());
            return;
          } catch (NotFoundException ex) {
            // it is not personal organization
          }
        }
        switch (event.getType()) {
          case MEMBER_ADDED:
            send((MemberAddedEventDto) event);
            break;
          case MEMBER_REMOVED:
            send((MemberRemovedEventDto) event);
            break;
          case ORGANIZATION_REMOVED:
            send((OrganizationRemovedEventDto) event);
            break;
          case ORGANIZATION_RENAMED:
            send((OrganizationRenamedEventDto) event);
        }
      }
    } catch (Exception ex) {
      LOG.error("Failed to send email notification '{}' cause : '{}'", ex.getMessage());
    }
  }

  @Inject public  OrganizationNotificationEmailSender(
      @Named("che.api") String apiEndpoint,
      MailSender mailSender,
      OrganizationManager organizationManager,
      UserManager userManager,
      OrganizationEmailNotifications emails);

}