package de.ivu.elect.presentation.wahl;

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

import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.wahl.entity.Wahl;
import de.ivu.elect.jee.entity.customdata.EmptyCustomData;
import de.ivu.elect.jee.presentation.dynamicform.FormBuilder;
import de.ivu.elect.jee.presentation.dynamicform.MessageProperty;
import de.ivu.elect.jee.presentation.redirect.Redirect;
import de.ivu.elect.presentation.AbstractElectEditView;
import de.ivu.elect.presentation.View;
import de.ivu.elect.presentation.security.NlPublicKeyEditView;
import de.ivu.elect.presentation.wahl.menu.NlBackupRestoreAction;

@RequestScoped
@Named(NlBackupRestoreView.COMPONENT_NAME)
@View(viewId = NlBackupRestoreView.VIEW_ID, useCase = UseCasePermission.CUSTOMER_2)
public class NlBackupRestoreView extends AbstractElectEditView<Wahl> {

  public static final String COMPONENT_NAME = "nlBackupRestoreView";

  public static final String VIEW_ID = "/wahl/nl-backup-restore.xhtml";

  private static final long serialVersionUID = 1L;

  @Inject
  private transient NlBackupRestoreAction nlBackupRestoreAction;

  @Override
  protected Wahl getEntity() {
    return new Wahl(EmptyCustomData.INSTANCE);
  }

  @Override
  protected void addProperties(FormBuilder formBuilder, Wahl entity) {
    formBuilder.addProperty(new MessageProperty(getMessage("nl.backup.restore.info")));
  }

  @Override
  public String delete() {
    return null;
  }

  @Override
  protected boolean isGebietBearbeitenRechtPruefen() {
    return false;
  }

  @Override
  protected boolean isSavePermissionVorhanden() {
    return false;
  }

  @Override
  public String save() {
    return null;
  }

  @Override
  public boolean isBtnCancelRendered() {
    return true;
  }

  @Override
  @Redirect
  public String cancel() {
    return getStartViewId();
  }

  public String getPageTitle() {
    return getPageHeader();
  }

  public String getPageHeader() {
    return getToggleLabel();
  }

  public String getToggleLabel() {
    return nlBackupRestoreAction.getLabelFinal();
  }

  public String getToggleIcon() {
    return nlBackupRestoreAction.getIcon();
  }

  @Redirect
  public String toggle() {
    if (nlBackupRestoreAction.isPossible()) {
      return nlBackupRestoreAction.doAction();
    }
    return getStartViewId();
  }

  @Override
  public boolean isBtnResetRendered() {
    return false;
  }
}
