/*
 * ElectionSubcategory
 *
 * Created on 03.04.2009
 * Copyright (c) 2009-2013 Kiesraad
 */
package de.ivu.wahl.wus.electioncategory;

import java.util.Arrays;

public enum ElectionSubcategory {
  /**
   * Should be used instead of null
   */
  NONE,

  EP,

  EK,

  TK,

  /**
   * Provinciale Staaten with more than one electoral district
   */
  PS2,

  /**
   * Provinciale Staaten with one electoral district
   */
  PS1,

  /**
   * Waterschapsverkiezing with 19 or more members
   */
  AB2,

  /**
   * Waterschapsverkiezing with less than 19 members
   */
  AB1,

  /**
   * Gemeenteraad with 19 or more members
   */
  GR2,

  /**
   * Gemeenteraad with less than 19 members
   */
  GR1,

  /**
   * Eilandsraad with less than 19 members
   */
  ER1,

  NR,

  PR,

  LR,

  IR,

  /**
   * Bestuurscommissie - Amsterdam
   */
  BC,

  /**
   * Gebiedscommissie - Rotterdam
   */
  GC;

  /**
   * @return the EML representation
   */
  public String getEmlRepresentation() {
    if (this.equals(NONE)) {
      return "";
    }
    return toString();
  }

  /**
   * @param emlRepresentation
   * @return the enum value for the given emlRepresentation. If no enum value is found, return NONE.
   */
  public static ElectionSubcategory fromEmlRepresentation(String emlRepresentation) {
    for (ElectionSubcategory c : ElectionSubcategory.values()) {
      if (c.getEmlRepresentation().equals(emlRepresentation)) {
        return c;
      }
    }
    return NONE;
  }

  public boolean isEK() {
    return this.equals(EK);
  }

  public int getPreferencialBarrierNumerator() {
    if (EP.equals(this)) {
      return 10;
    } else if (Arrays.asList(EK, GC).contains(this)) {
      return 100;
    } else if (Arrays.asList(GR1, ER1, BC).contains(this)) {
      return 50;
    } else {
      return 25;
    }
  }

  public int getPreferencialBarrierDenominator() {
    return 100;
  }
}