
package de.ivu.elect.presentation.dokumente;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import de.ivu.elect.business.datei.entity.FileType;
import de.ivu.elect.business.datei.entity.FileTypeResolver;

public class DokumentVorlageCreateAllowedFileTypes implements Serializable {

  private static final long serialVersionUID = 1L;

  @Inject
  private transient FileTypeResolver fileTypeResolver;

  public DokumentVorlageCreateAllowedFileTypes() {
    super();
  }

  public String getAllowedFileTypeRegEx() {
    return fileTypeResolver.getFileTypesHtmlRegEx(getAllowedFileTypes());
  }

  public String getAllowedFileTypeHtmlAccept() {
    return fileTypeResolver.getFileTypesHtmlAccept(getAllowedFileTypes());
  }

  public String getAllowedFileTypeNames() {
    List<FileType> fileTypes = new ArrayList<>(getAllowedFileTypes());

    if (fileTypes.contains(FileType.ZIP) && fileTypes.contains(FileType.DVZ)) {
      // ELECT-5759, nur aus der Anzeige, nicht dem RegEx-Filter (!), die ZIP-Datei entfernen.
      fileTypes.remove(FileType.ZIP);
    }

    return fileTypeResolver.formatFileTypes(fileTypes);
  }

  public List<FileType> getAllowedFileTypes() {
    List<FileType> result = new ArrayList<>();
    result.add(FileType.ODT);
    result.add(FileType.ODS);
    result.add(FileType.OTT);

    return result;
  }
}
