package de.ivu.elect.business.dokumente.entity;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.ivu.elect.business.dokumente.control.DokumentExtraFileOutput;
import de.ivu.elect.business.dokumente.control.ProgressMonitor;


import static de.ivu.elect.business.dokumente.entity.DokumentGenerierenProgress.ERSTELLE_EXTRA_FILE;

/**
 *  on 15.06.2016.
 */
public class InMemoryDokumentExtraFileOutput implements DokumentExtraFileOutput {

  private static final Logger LOG = LoggerFactory.getLogger(InMemoryDokumentExtraFileOutput.class);

  private final ProgressMonitor monitor;

  private final List<FileContent> files = new ArrayList<>();

  public InMemoryDokumentExtraFileOutput(ProgressMonitor monitor) {
    this.monitor = monitor;
  }

  @Override
  public void appendFile(FileContent fileContent) {
    files.add(fileContent);
    LOG.info("Datei hinzugefuegt: " + fileContent.getFilename());
    monitor.progress(ERSTELLE_EXTRA_FILE, fileContent.getFilename());
  }

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

  @Override
  public List<FileContent> getFiles() {
    return files;
  }
}
