
package de.ivu.elect.business.personenpruefung.entity;

import static java.util.Collections.singletonList;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.ivu.elect.jee.presentation.dynamicform.LambdaEnumProperty;
import de.ivu.elect.jee.presentation.dynamicform.Property;
import de.ivu.elect.jee.protokollierung.AttributTyp;

public abstract class AbstractEnumPersonPruefungKonfigurationCustomData<E extends Enum<E>> extends AbstractPersonPruefungKonfigurationCustomData {

  private static final long serialVersionUID = 1L;

  private E value;

  protected AbstractEnumPersonPruefungKonfigurationCustomData(E defaultValue) {
    super();

    this.value = defaultValue;
  }

  public E getValue() {
    return value;
  }

  public void setValue(E value) {
    notifyEntity("AbstractEnumPersonPruefungKonfigurationCustomData.value", AttributTyp.ENUM, this.value, this.value = value);
  }

  protected abstract Class<E> getEnumClass();

  protected abstract List<E> getPropertyValues();

  protected abstract String getPropertyLabelMsgKey();

  protected String getPropertyLabel() {
    return getMessage(getPropertyLabelMsgKey());
  }

  protected boolean isPropertyValueRequired() {
    return true;
  }

  @Override
  public Map<PersonPruefungKonfigurationCustomDataKategorie, List<Object>> getParameters() {
    Map<PersonPruefungKonfigurationCustomDataKategorie, List<Object>> result = new HashMap<>();
    result.put(PersonPruefungKonfigurationCustomDataKategorie.ENUM_SELECT_ONE, singletonList(getValue()));

    return result;
  }

  @Override
  public List<Property> getProperties(PersonPruefungKonfigurationPropertyContext context) {
    List<Property> result = new ArrayList<>();
    result.add(new LambdaEnumProperty<>(getPropertyLabel(), isPropertyValueRequired(), this::setValue, this::getValue, getEnumClass(), getPropertyValues()));

    return result;
  }
}
