
package de.ivu.elect.presentation.gebietsbaum;

import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.inject.Inject;

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

import de.ivu.elect.business.wahl.boundary.WahlSelectChangeEvent;
import de.ivu.elect.business.wahl.boundary.WahlterminSelectChangeEvent;

@GroupedConversationScoped
@ConversationGroup(NlGebietCreateViewConversationStore.class)
public class NlGebietCreateViewConversationStore implements java.io.Serializable {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient GroupedConversation conversation;

  private boolean briefwahlbezirkAuslandCreated;

  public NlGebietCreateViewConversationStore() {
    super();
  }

  public boolean isBriefwahlbezirkGemeindeCreated() {
    return !isBriefwahlbezirkAuslandCreated();
  }

  public void setBriefwahlbezirkGemeindeCreated() {
    this.briefwahlbezirkAuslandCreated = false;
  }

  public boolean isBriefwahlbezirkAuslandCreated() {
    return briefwahlbezirkAuslandCreated;
  }

  public void setBriefwahlbezirkAuslandCreated() {
    this.briefwahlbezirkAuslandCreated = true;
  }

  public void close() {
    briefwahlbezirkAuslandCreated = false;

    conversation.close();
  }

  public void onWahlSelectChangeEvent(@Observes(notifyObserver = Reception.IF_EXISTS) WahlSelectChangeEvent event) {
    close();
  }

  public void onWahlterminSelectChangeEvent(@Observes(notifyObserver = Reception.IF_EXISTS) WahlterminSelectChangeEvent event) {
    close();
  }
}
