package de.ivu.elect.presentation.wahl.form;

import java.util.List;

import javax.faces.convert.Converter;

import de.ivu.elect.business.wahl.entity.WahlConstants;
import de.ivu.elect.business.wahl.entity.Wahlart;
import de.ivu.elect.jee.faces.EntityConverter;
import de.ivu.elect.jee.presentation.dynamicform.AbstractSelectOneMenuProperty;


import static java.util.Objects.nonNull;

/**
 *  on 09.08.2016.
 */
public abstract class AbstractWahlartSelectOneMenuProperty extends AbstractSelectOneMenuProperty<Wahlart> {

  private final List<Wahlart> wahlarten;

  protected AbstractWahlartSelectOneMenuProperty(List<Wahlart> wahlarten) {
    this.wahlarten = wahlarten;
  }

  @Override
  public Converter getDefaultConverter() {
    return EntityConverter.getInstance();
  }

  @Override
  public List<Wahlart> getValues() {
    return wahlarten;
  }


  @Override
  public String getItemLabel(Wahlart wahlart) {
    if (nonNull(wahlart)) {
      return getMessage("wahlart.select.menu.item.label", wahlart.getNameGuiEindeutig(), wahlart.getNameGui(), wahlart.getName());
    }

    return "";
  }

  @Override
  public String getDefaultLabel() {
    return getMessage(WahlConstants.MESSAGE_KEY_WAHLART_ID_EINZAHL);
  }

  @Override
  public boolean getDefaultRequired() {
    return !WahlConstants.WAHLART_ID_NULLABLE;
  }

  @Override
  public boolean hasNoSelectionItem() {
    return true;
  }
}
