
package de.ivu.elect.exchange.gebietsbaum.csv;

import java.io.InputStream;
import java.util.List;

import javax.annotation.Nonnull;
import javax.inject.Inject;

import de.ivu.elect.business.datei.entity.FileType;
import de.ivu.elect.business.exchange.control.FileFormat;
import de.ivu.elect.business.exchange.control.FileKonfiguration;
import de.ivu.elect.business.gebietsbaum.control.Gebietsbaum;
import de.ivu.elect.business.gebietsbaum.control.GebietsbaumExchangeContext;
import de.ivu.elect.exchange.CsvImportMapper;
import de.ivu.elect.exchange.csv.CsvMarshaller;
import de.ivu.elect.exchange.gebietsbaum.GebietDTO;

public abstract class AbstractGebietsbaumCsvImportMapper<T extends GebietDTO> extends AbstractGebietsbaumVonGebietDTOImportMapper<T>
    implements
      CsvImportMapper<Gebietsbaum, GebietsbaumExchangeContext> {

  @Inject
  private transient CsvMarshaller csvMarshaller;

  protected AbstractGebietsbaumCsvImportMapper() {
    super();
  }

  @Override
  public FileFormat getFileFormat() {
    return new FileFormat(getFileFormatName(), FileType.CSV);
  }

  protected abstract String getFileFormatName();

  @Override
  protected List< ? extends T> deserializeDtos(InputStream is, FileKonfiguration fileKonfiguration) {
    return csvMarshaller.deserialize(getDtoClass(), is, fileKonfiguration);
  }

  @Override
  public List<String> getCsvColumnHeaders(GebietsbaumExchangeContext context) {
    return csvMarshaller.extractHeader(getDtoClass());
  }

  @Nonnull
  protected abstract Class< ? extends T> getDtoClass();
}
