
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 javax.annotation.Nullable;

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

public abstract class AbstractLongPersonPruefungKonfigurationCustomData extends AbstractPersonPruefungKonfigurationCustomData {

  private static final long serialVersionUID = 1L;

  private Long value;

  protected AbstractLongPersonPruefungKonfigurationCustomData(Long defaultValue) {
    super();

    this.value = defaultValue;
  }

  public Long getValue() {
    return value;
  }

  public void setValue(Long value) {
    notifyEntity("AbstractLongPersonPruefungKonfigurationCustomData.value", AttributTyp.LONG, this.value, this.value = value);
  }

  @Nullable
  protected abstract Long getPropertyMinValue();

  @Nullable
  protected abstract Long getPropertyMaxValue();

  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.LONG, singletonList(getValue()));

    return result;
  }

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

    return result;
  }
}
