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

import de.ivu.elect.business.personenpruefung.entity.PersonPruefungKonfiguration;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.jee.entity.customdata.EmptyCustomData;
import de.ivu.elect.presentation.View;
import de.ivu.elect.presentation.personenpruefung.PersonPruefungKonfigurationEditView;

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

@Named(PersonPruefungKonfigurationEditAction.COMPONENT_NAME)
public class PersonPruefungKonfigurationEditAction extends AbstractPersonPruefungKonfigurationAction {

  public static final String COMPONENT_NAME = "personPruefungKonfigurationEditAction";

  @View
  @Inject
  private transient PersonPruefungKonfigurationEditView personPruefungKonfigurationEditView;

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

  @Override
  protected boolean isDisabledInternal(@Nonnull PersonPruefungKonfiguration personPruefungKonfiguration) {
    return super.isDisabledInternal(personPruefungKonfiguration) || !personPruefungKonfiguration.getStatus().isAktiv()
        || personPruefungKonfiguration.getCustomData() instanceof EmptyCustomData;
  }

  @Override
  protected String doIt(PersonPruefungKonfiguration personPruefungKonfiguration) {
    return personPruefungKonfigurationEditView.edit(personPruefungKonfiguration);
  }

  @Override
  public String getLabelKey() {
    return "entity.edit.action.edit";
  }

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