
package de.ivu.elect.presentation.statistik;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;

import de.ivu.elect.business.statistik.boundary.StatistikLaufBoundaryCreate;
import de.ivu.elect.business.statistik.entity.StatistikLauf;
import de.ivu.elect.business.statistik.entity.StatistikLaufMeta;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.security.UseCaseSecure;
import de.ivu.elect.presentation.View;
import de.ivu.elect.jee.presentation.redirect.Redirect;

@Named(AbstractStatistikLaufCreateNoScopeView.COMPONENT_NAME)
@View(viewId = AbstractStatistikLaufCreateNoScopeView.VIEW_ID, useCase = UseCasePermission.STATISTIK_LAUF_CREATE)
public abstract class AbstractStatistikLaufCreateNoScopeView extends de.ivu.elect.presentation.AbstractElectCreateView<StatistikLauf> {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "statistikLaufCreateView";

  public static final String VIEW_ID = "/statistik/statistik-lauf-create.xhtml";

  public static final String PARENT_VIEW_ID = "/statistik/statistik-lauf-search.xhtml";

  @Inject
  protected transient StatistikLaufBoundaryCreate create;

  protected StatistikLauf entity;

  @Inject
  protected transient StatistikLaufMeta entityMeta;

  
  @PostConstruct
  public void init() {
    setEntity(new  StatistikLauf());
  }

  

  public StatistikLauf getEntity() {
    return entity;
  }

  protected void setEntity(StatistikLauf entity) {
    this.entity = entity;
  }

  @Redirect
  @UseCaseSecure(UseCasePermission.STATISTIK_LAUF_CREATE)
  public String save() {
    callSave(getEntity());

    addMessageSaveSuccess(getEntity());

    resetStateAfterAction();

    return goBack(getParentViewId());
  }

  protected void callSave(StatistikLauf entity) {
    create.save(entity);
  }

  protected void addMessageSaveSuccess(StatistikLauf entity) {
    addInfoMessage("entity.create.action.save.success.message", entityMeta.getEinzahlMessage());
  }

  public boolean isBtnSaveRendered() {
    return hasPermission(UseCasePermission.STATISTIK_LAUF_CREATE);
  }

  @Redirect
  public String reset() {
    resetStateAfterAction();

    init();

    return getViewId();
  }

  public boolean isBtnResetRendered() {
    return true;
  }

  @Redirect
  public String cancel() {
    resetStateAfterAction();

    return goBack(getParentViewId());
  }

  public boolean isBtnCancelRendered() {
    return true;
  }

  protected String getViewId() {
    return VIEW_ID;
  }

  protected String getParentViewId() {
    return PARENT_VIEW_ID;
  }

  protected void resetStateAfterAction() {
    // Do nothing.
  }
}
