/*
 * Decision
 *
 * Created on 25.02.2009
 * Copyright (c) 2009 Kiesraad
 */
package de.ivu.wahl.result.drawlots;

import de.ivu.wahl.result.Util;
import de.ivu.wahl.result.i18n.MessageKeys;
import de.ivu.wahl.result.i18n.Messages;

import java.util.Collections;
import java.util.List;

/**
 * A {@link Decision} holds information about the event that one alternative out of a given list of
 * alternatives was drawn.
 *
 */
public class Decision {

  private final DecisionType type;
  private final List<DrawingLotsAlternative> alternatives;
  private final int selectedAlternative; // 0-based index

  public Decision(final DecisionType type,
                  final List<? extends DrawingLotsAlternative> alternatives,
                  final int selectedAlternative) {
    this.type = type;
    this.alternatives = Collections.unmodifiableList(alternatives);
    this.selectedAlternative = selectedAlternative;
  }

  public DecisionType getType() {
    return type;
  }

  /**
   * @return the list of alternatives from which one alternative was drawn.
   */
  public List<DrawingLotsAlternative> getAlternatives() {
    return alternatives;
  }

  /**
   * @return the 0-based index of the alternative that was drawn
   */
  public int getSelectedIndex() {
    return selectedAlternative;
  }

  @Override
  public String toString() {
    return Messages
            .bind(MessageKeys.Result_Tracelog_DrawingLotsAccordingToP_0_Selected_1_Alternatives_2,
                    type.getId(),
                    selectedAlternative + 1,
                    Util.displayNamedObjects(alternatives));
  }
}
