package de.ivu.elect.presentation.email.action;

import de.ivu.elect.business.email.boundary.EmailExtendedDAO;
import de.ivu.elect.business.email.entity.EmailStatusType;
import de.ivu.elect.business.email.entity.EmailVorgang;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.presentation.View;
import de.ivu.elect.presentation.email.EmailVorgangEditView;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Named;

@Named(EmailVorgangSendeFehlerhafteErneutAction.COMPONENT_NAME)
public class EmailVorgangSendeFehlerhafteErneutAction extends AbstractEmailVorgangAction {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "emailVorgangSendeFehlerhafteErneutAction";

  @View
  @Inject
  private EmailVorgangEditView emailVorgangEditView;

  @Inject
  private transient EmailExtendedDAO emailExtendedDAO;

  public EmailVorgangSendeFehlerhafteErneutAction() {
    super();
  }

  @Override
  protected UseCasePermission getRequiredPermission() {
    return UseCasePermission.EMAIL_VORGANG_EDIT;
  }

  @Override
  protected boolean isDisabledInternal(@Nonnull EmailVorgang entity) {
    return emailExtendedDAO.findByCountEmailVorgangAndStatus(entity, EmailStatusType.FEHLER) < 1;
  }

  @Override
  protected String doIt(EmailVorgang emailVorgang) {
    emailVorgangEditView.setEntity(emailVorgang);

    return null;
  }

  @Override
  protected boolean isFireChangeEvent() {
    return true;
  }

  @Override
  public String getDialogName() {
    return "SendeFehlerhafteErneutConfirm";
  }

  @Override
  public String getLabelKey() {
    return "email.vorgang.action.sende.fehlerhafte.erneut";
  }

  @Override
  public String getIcon() {
    return appIcons.getIconSend();
  }
}
