
package de.ivu.elect.presentation.dokumente;

import java.util.Collections;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import de.ivu.elect.business.datei.entity.FileType;
import de.ivu.elect.business.datei.entity.FileTypeResolver;
import de.ivu.elect.business.dokumente.entity.DokumentVorlage;
import de.ivu.elect.business.dokumente.entity.DokumentVorlageArt;
import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.presentation.View;


import static org.apache.commons.lang3.StringUtils.isBlank;

@Named(DokumentVorlageLeerformularCreateView.COMPONENT_NAME)
@View(viewId = DokumentVorlageLeerformularCreateView.VIEW_ID, useCase = UseCasePermission.DOKUMENT_VORLAGE_CREATE)
public class DokumentVorlageLeerformularCreateView extends AbstractElectDokumentVorlageCreateView {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "dokumentVorlageLeerformularCreateView";

  public static final String VIEW_ID = "/dokumente/dokument-vorlage-leerformular-create.xhtml";

  @Inject
  private transient FileTypeResolver fileTypeResolver;

  @Override
  public List<DokumentVorlageArt> getDokumentVorlageArten() {
    return Collections.singletonList(DokumentVorlageArt.LEERFORMULAR);
  }

  @Override
  protected void bestimmeArtUndName(String fileName, DokumentVorlage dokumentVorlage) {
    if (isBlank(dokumentVorlage.getName())) {
      dokumentVorlage.setName(DokumentVorlageArt.getDokumentVorlageName(fileName, null));
    }
  }

  @Override
  protected String getViewId() {
    return VIEW_ID;
  }

  @Override
  protected String getAllowedFileTypeNames() {
    return fileTypeResolver.formatFileTypes(getFileUploadFileTypes());
  }

  @Override
  public String getFileUploadAllowTypes() {
    return fileTypeResolver.getFileTypesHtmlRegEx(getFileUploadFileTypes());
  }

  @Override
  public String getFileUploadAccept() {
    return fileTypeResolver.getFileTypesHtmlAccept(getFileUploadFileTypes());
  }

  @Override
  public List<FileType> getFileUploadFileTypes() {
    return Collections.singletonList(FileType.ALL);
  }

  @Override
  protected void addMessageSaveSuccess(DokumentVorlage entity) {
    addInfoMessage("entity.create.action.save.success.message", messages.getMessageForMessageKey("entity.leerformular"));
  }

}
