
package de.ivu.elect.business.kandidatur.control;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import de.ivu.elect.business.kandidatur.entity.Listenkandidatur;
import de.ivu.elect.business.wahlvorschlag.entity.ListeTK;

public class ListenkandidaturNamenUndListeTK {

  private final String rufname;
  private final String familienname;
  private final ListeTK listeTk;

  public ListenkandidaturNamenUndListeTK(String rufname, String familienname, ListeTK listeTk) {
    super();

    this.rufname = rufname;
    this.familienname = familienname;
    this.listeTk = listeTk;
  }

  public String getRufname() {
    return rufname;
  }

  public String getFamilienname() {
    return familienname;
  }

  public ListeTK getListeTk() {
    return listeTk;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + (listeTk == null ? 0 : listeTk.hashCode());
    result = prime * result + (familienname == null ? 0 : familienname.hashCode());
    result = prime * result + (rufname == null ? 0 : rufname.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }

    ListenkandidaturNamenUndListeTK other = (ListenkandidaturNamenUndListeTK) obj;
    if (listeTk == null) {
      if (other.listeTk != null) {
        return false;
      }
    } else if (!listeTk.equals(other.listeTk)) {
      return false;
    }

    if (familienname == null) {
      if (other.familienname != null) {
        return false;
      }
    } else if (!familienname.equals(other.familienname)) {
      return false;
    }

    if (rufname == null) {
      if (other.rufname != null) {
        return false;
      }
    } else if (!rufname.equals(other.rufname)) {
      return false;
    }

    return true;
  }

  @Override
  public String toString() {
    return "ListenkandidaturNamenUndListeTK [rufname=" + rufname + ", familienname=" + familienname + ", listeTk=" + "null"; //listeTk + "]";
  }

  public static ListenkandidaturNamenUndListeTK createFromListenkandidatur(Listenkandidatur listenkandidatur) {
    return new ListenkandidaturNamenUndListeTK(listenkandidatur.getRufname(), listenkandidatur.getFamilienname(), listenkandidatur.getListe().getListeTK());
  }

  public static Map<ListenkandidaturNamenUndListeTK, Listenkandidatur> mappeListenkandidaturNachTK(Collection<Listenkandidatur> listenkandidaturen) {
    Map<ListenkandidaturNamenUndListeTK, Listenkandidatur> result = new HashMap<>();
    for (Listenkandidatur listenkandidatur : listenkandidaturen) {
      result.put(createFromListenkandidatur(listenkandidatur), listenkandidatur);
    }
    return result;
  }
}
