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

import static java.util.Objects.requireNonNull;

import java.io.Serializable;

import javax.annotation.Nonnull;

import de.ivu.elect.business.person.entity.Personendaten;
import de.ivu.elect.presentation.menu.AbstractActionEntry;

public abstract class AbstractPersonendatenActionResolver implements Serializable {

  private static final long serialVersionUID = 1L;

  protected AbstractPersonendatenActionResolver() {
    super();
  }

  public <E extends Personendaten> boolean isActionPossible(E personendaten) {
    return hasAction(personendaten) && getAction(personendaten).isActionPossible(personendaten);
  }

  private <E extends Personendaten> boolean hasAction(E personendaten) {
    try {
      return getAction(personendaten) != null;
    } catch (Exception ignored) {
    }

    return false;
  }

  protected <E extends Personendaten> AbstractActionEntry<E> getAction(E personendaten) {
    requireNonNull(personendaten, "Personendaten may NOT be null");

    return resolveAction(personendaten);
  }

  protected abstract <E extends Personendaten> AbstractActionEntry<E> resolveAction(@Nonnull Personendaten personendaten);
}
