
package de.ivu.elect.presentation.entschaedigung;

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

import de.ivu.elect.business.entschaedigung.boundary.EntschaedigungBoundaryCreate;
import de.ivu.elect.business.entschaedigung.entity.Entschaedigung;
import de.ivu.elect.business.entschaedigung.entity.EntschaedigungMeta;
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(AbstractEntschaedigungCreateNoScopeView.COMPONENT_NAME)
@View(viewId = AbstractEntschaedigungCreateNoScopeView.VIEW_ID, useCase = UseCasePermission.ENTSCHAEDIGUNG_CREATE)
public abstract class AbstractEntschaedigungCreateNoScopeView extends de.ivu.elect.presentation.AbstractElectCreateView<Entschaedigung> {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "entschaedigungCreateView";

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

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

  @Inject
  protected transient EntschaedigungBoundaryCreate create;

  protected Entschaedigung entity;

  @Inject
  protected transient EntschaedigungMeta entityMeta;

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

  

  public Entschaedigung getEntity() {
    return entity;
  }

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

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

    addMessageSaveSuccess(getEntity());

    resetStateAfterAction();

    return goBack(getParentViewId());
  }

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

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

  public boolean isBtnSaveRendered() {
    return hasPermission(UseCasePermission.ENTSCHAEDIGUNG_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.
  }
}
