
package de.ivu.elect.jee.presentation.dynamicform;

import java.util.Date;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class LambdaTimestampProperty extends AbstractTimestampProperty {

  private final String defaultLabel;

  private final Date defaultValue;

  private final boolean defaultRequired;

  private final Consumer<Date> setter;

  private final Supplier<Date> getter;

  public LambdaTimestampProperty(String defaultLabel, boolean defaultRequired, Consumer<Date> setter, Supplier<Date> getter) {
    this(defaultLabel, null, defaultRequired, setter, getter);
  }

  public LambdaTimestampProperty(String defaultLabel, Date defaultValue, boolean defaultRequired, Consumer<Date> setter, Supplier<Date> getter) {
    super();

    this.defaultLabel = defaultLabel;
    this.defaultValue = defaultValue;
    this.defaultRequired = defaultRequired;

    this.setter = setter;
    this.getter = getter;
  }

  @Override
  public Date getDefaultValue() {
    return defaultValue;
  }

  @Override
  public Date getValue() {
    return getter.get();
  }

  @Override
  public void setValue(Date value) {
    setter.accept(value);
  }

  @Override
  public String getDefaultLabel() {
    return defaultLabel;
  }

  @Override
  public boolean getDefaultRequired() {
    return defaultRequired;
  }
}
