package de.ivu.elect.business.internet.boundary;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import javax.inject.Inject;

import de.ivu.elect.business.internet.entity.InternetWidget;
import de.ivu.elect.business.internet.entity.InternetWidgetCustomData;
import de.ivu.elect.business.internet.entity.InternetWidgetFile;
import de.ivu.elect.business.internet.entity.InternetWidgetFileEntity;

public class InternetWidgetFileSearch {

  @Inject
  protected transient InternetWidgetExtendedDAO dao;

  public List<InternetWidgetFileEntity> getSearchResult(InternetWidget entityNotAttached) {

    return dao.attach(entityNotAttached).getCustomData(InternetWidgetCustomData.class).getFiles().stream()
        .sorted(Comparator.comparing(InternetWidgetFile::getPosition))
        .map(InternetWidgetFileEntity::new)
        .collect(Collectors.toList());

  }
}
