
package de.ivu.elect.business.wahlrechtspruefung.boundary;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.deltaspike.core.api.scope.ConversationGroup;

import de.ivu.elect.business.wahlrechtspruefung.entity.Pruefkriterium;

@RequestScoped
@Named(PruefkriteriumConversationSelect.COMPONENT_NAME)
public class PruefkriteriumConversationSelect implements java.io.Serializable {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "pruefkriteriumConversationSelect";

  @Inject
  protected transient PruefkriteriumExtendedDAO entityDAO;

  @Inject
  @ConversationGroup(PruefkriteriumConversationStore.class)
  protected transient PruefkriteriumConversationStore conversationStore;

  public PruefkriteriumConversationSelect() {
    super();
  }

  public boolean isSelected() {
    return getEntityPK() != null;
  }

  public Pruefkriterium getEntity() {
    return getEntityInternal();
  }

  private Pruefkriterium getEntityInternal() {
    if (getEntityPK() == null) {
      return null;
    }

    return attach(getEntityPK());
  }

  public void setEntity(Pruefkriterium entity) {
    setEntityAttached(attach(entity));
  }

  public void setEntity( de.ivu.elect.business.wahlrechtspruefung.entity.PruefkriteriumPK  pk) {
    setEntityAttached(attach(pk));
  }

  protected void setEntityAttached(Pruefkriterium entity) {
    if(entity == null) {
      setEntityPK(null);
    } else {
      setEntityPK(entity.getPk());
    }
  }

  public
    de.ivu.elect.business.wahlrechtspruefung.entity.PruefkriteriumPK
   getEntityPK() {
    return conversationStore.getEntityPK();
  }

  public void setEntityPK(
    de.ivu.elect.business.wahlrechtspruefung.entity.PruefkriteriumPK
   entityPK) {
    conversationStore.setEntityPK(entityPK);
  }

  protected Pruefkriterium attach(Pruefkriterium entity) {
    if (entity == null){
      return null;
    }

    return attach(entity.getPk());
  }

  protected Pruefkriterium attach( de.ivu.elect.business.wahlrechtspruefung.entity.PruefkriteriumPK  pk) {
    if (pk == null) {
      return null;
    }

    return entityDAO.findByPrimaryKey(pk);
  }

  public void clearEntity() {
    setEntityPK(null);

    conversationStore.close();
  }
}
