package eu.eudat.logic.managers;

import eu.eudat.models.data.files.ContentFile;
import eu.eudat.logic.services.helpers.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * Created by ikalyvas on 3/15/2018.
 */
@Component
public class FileManager {

    private FileStorageService fileStorageService;

    @Autowired
    public FileManager(FileStorageService fileStorageService) {
        this.fileStorageService = fileStorageService;
    }

    public List<ContentFile> saveTempFile(MultipartFile file[]) throws IOException {
        return fileStorageService.writeToTempFileSystem(file);
    }

    public Resource getFile(String filename, String type, String location) throws IOException {
        return fileStorageService.readFromFilesystem(filename, type, location);
    }
}
