package org.bench4q.agent.plugin;

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

import org.bench4q.share.helper.FileHelper;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class ParameterFileCollector {
	private static final String FILE_SEPARATOR = System
			.getProperty("file.separator");

	public void collectParamFiles(List<MultipartFile> files, UUID runId)
			throws IOException {
		for (MultipartFile file : files) {
			file.transferTo(new File(guardDirExists(runId)
					+ file.getOriginalFilename()));
		}
	}

	private String guardDirExists(UUID runId) {
		String dirPath = "ScenarioParameters" + FILE_SEPARATOR
				+ runId.toString() + FILE_SEPARATOR;
		FileHelper.guardFolderExist(dirPath);
		return dirPath;
	}
}
