
package de.ivu.elect.presentation.wertelisten;

import static java.util.Arrays.asList;

import java.io.Serializable;
import java.util.List;

import de.ivu.elect.business.wertelisten.boundary.WertelistenSearchParameters;
import de.ivu.elect.business.wertelisten.entity.WertelistenArt;
import de.ivu.elect.business.wertelisten.entity.WertelistenConstants;
import de.ivu.elect.jee.presentation.dynamicform.AbstractEnumProperty;
import de.ivu.elect.jee.presentation.dynamicform.AbstractStringProperty;
import de.ivu.elect.jee.presentation.search.AbstractSearchParameters;

public class WertelistenSearchParametersProperties implements Serializable {

  private static final long serialVersionUID = 1L;

  private static final String WILDCARD_TOOLTIP_MSG_KEY = AbstractSearchParameters.WILDCARD_TOOLTIP_MSG_KEY;

  private final WertelistenSearchParameters searchParameters;

  public WertelistenSearchParametersProperties(WertelistenSearchParameters searchParameters) {
    this.searchParameters = searchParameters;
  }

  public WertelistenNameProperty getWertelistenNameProperty() {
    return new WertelistenNameProperty(searchParameters);
  }

  public WertelistenWertelistenArtProperty getWertelistenWertelistenArtProperty() {
    return new WertelistenWertelistenArtProperty(searchParameters);
  }

  public final class WertelistenNameProperty extends AbstractStringProperty {

    private final WertelistenSearchParameters searchParameters;

    public WertelistenNameProperty(WertelistenSearchParameters searchParameters) {
      this.searchParameters = searchParameters;
    }

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

    @Override
    public String getDefaultLabel() {
      return getMessage(WertelistenConstants.MESSAGE_KEY_NAME_EINZAHL);
    }

    @Override
    public String getValue() {
      return searchParameters.getName();
    }

    @Override
    public void setValue(String value) {
      searchParameters.setName(value);
    }

    @Override
    public int getDefaultMaxLength() {
      return WertelistenConstants.NAME_MAX_LENGTH;
    }

    @Override
    public String getDefaultTooltip() {
      return getMessage(WILDCARD_TOOLTIP_MSG_KEY);
    }
  }

  public final class WertelistenWertelistenArtProperty extends AbstractEnumProperty<WertelistenArt> {

    private final WertelistenSearchParameters searchParameters;

    public WertelistenWertelistenArtProperty(WertelistenSearchParameters searchParameters) {
      this.searchParameters = searchParameters;
    }

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

    @Override
    protected Class<WertelistenArt> getEnumClass() {
      return WertelistenArt.class;
    }

    @Override
    public String getDefaultLabel() {
      return getMessage(WertelistenConstants.MESSAGE_KEY_WERTELISTEN_ART_EINZAHL);
    }

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

    @Override
    public WertelistenArt getValue() {
      return searchParameters.getWertelistenArt();
    }

    @Override
    public void setValue(WertelistenArt value) {
      searchParameters.setWertelistenArt(value);
    }

    @Override
    public List<WertelistenArt> getValues() {
      return asList(WertelistenArt.values());
    }
  }
}
