
package de.ivu.elect.exchange;

import static java.util.Arrays.asList;

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

import javax.inject.Inject;

import de.ivu.elect.jee.faces.Messages;

public abstract class AbstractLocalisedEnumExchangeMapper<E extends Enum< ? >> extends AbstractEnumExchangeMapper<E> {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient Messages messages;

  protected AbstractLocalisedEnumExchangeMapper() {
    super();
  }

  @Override
  protected Map<E, List<String>> getValuePerAliases() {
    Map<E, List<String>> result = new HashMap<>();

    for (E value : values()) {
      result.put(value, asList(value.name(), getMessages().lokalisiere(value)));
    }

    return result;
  }

  protected abstract List<E> values();

  @Override
  protected String getAliasUnbekannt() {
    return getValuePerAliases().get(getValueUnbekannt()).get(0);
  }

  public Messages getMessages() {
    return messages;
  }
}
