package entities;

import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

@ManagedBean(name = "modul")
@RequestScoped
public class Modul implements Serializable {

  private static final long serialVersionUID = 1L;
  private int nr;
  private String name;

  public Modul() {
  }

  public Modul(int nr, String name) {
    this.nr = nr;
    this.name = name;
  }

  public void pruefe(FacesContext context,
          UIComponent component, Object value)
          throws ValidatorException {
    if (((String) value).equals("OOAD")) {
      throw new ValidatorException(new FacesMessage(
              FacesMessage.SEVERITY_ERROR, "oweh", "ole ole"));
    }
  }

  public String uebernehmen() {
    return "./ausgabe.xhtml";
  }

  public String eingeben() {
    return "./index.xhtml";
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getNr() {
    return nr;
  }

  public void setNr(int nr) {
    this.nr = nr;
  }

  @Override
  public boolean equals(Object object) {
    if (object == null || !(object instanceof Modul)) {
      return false;
    }
    Modul other = (Modul) object;
    if (this.nr != other.nr || !this.name.equals(other.name)) {
      return false;
    }
    return true;
  }

  @Override // generieren lassen
  public int hashCode() {
    int hash = 5;
    hash = 47 * hash + this.nr;
    hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
    return hash;
  }

  @Override
  public String toString() {
    return name + "(" + nr + ")";
  }
}
