package de.ivu.elect.presentation.gebietsbaum.tree;

import java.io.Serializable;

import org.apache.deltaspike.core.api.scope.ViewAccessScoped;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;

import de.ivu.elect.business.wahl.entity.WahlPK;
import de.ivu.elect.business.wahl.entity.WahlterminPK;

@ViewAccessScoped
public class LazyGebietsbaumStore implements Serializable {

  private static final long serialVersionUID = 1L;

  private DefaultTreeNode root;

  private TreeNode selectedNode;

  private LazyGebietsbaumStoreReferenz lastGebietsbaumStoreReferenz = new LazyGebietsbaumStoreReferenz(null, null, null);

  private boolean treeReady = false;

  public DefaultTreeNode getRoot() {
    return root;
  }

  public void setRoot(DefaultTreeNode root) {
    this.root = root;
  }

  public TreeNode getSelectedNode() {
    return selectedNode;
  }

  public void setSelectedNode(TreeNode selectedNode) {
    this.selectedNode = selectedNode;
  }

  public boolean requestViewWahlOrWahlterminChanged(String currentViewId, WahlterminPK wahlterminPK, WahlPK wahlPK) {
    LazyGebietsbaumStoreReferenz compare = new LazyGebietsbaumStoreReferenz(currentViewId, wahlterminPK, wahlPK);
    if (compare.equals(lastGebietsbaumStoreReferenz)) {
      return false;
    }
    lastGebietsbaumStoreReferenz = compare;
    return true;
  }

  public void setTreeReady(boolean treeReady) {
   this.treeReady = treeReady;
  }

  public boolean isTreeReady() {
    return treeReady;
  }
}
