package kr.co.jinwoosi.clfd.framework.file.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import kr.co.jinwoosi.clfd.framework.base.service.impl.BaseServiceImpl;
import kr.co.jinwoosi.clfd.framework.file.mapper.FileMapper;
import kr.co.jinwoosi.clfd.framework.file.model.FileInfo;
import kr.co.jinwoosi.clfd.framework.file.model.FileItem;
import kr.co.jinwoosi.clfd.framework.file.model.FileItemSearch;
import kr.co.jinwoosi.clfd.framework.file.model.FileSearch;
import kr.co.jinwoosi.clfd.framework.file.service.FileItemService;
import kr.co.jinwoosi.clfd.framework.file.service.FileService;

@Service(value="fileService")
public class FileServiceImpl extends BaseServiceImpl<FileInfo, FileSearch, FileMapper> implements FileService {

	@Resource (name="fileItemService")
	private FileItemService fileItemService;
	
	@Override
	@Resource (name="fileMapper")
	protected void setMapper (FileMapper mapper) {
		super.setMapper (mapper);
	}
	
	
	@Override
	public FileInfo select(FileSearch fileSearch) {
		FileInfo file = super.select(fileSearch);
		FileItemSearch fileItemSearch = new FileItemSearch();
		fileItemSearch.setFileId(file.getFileId());
		file.setFileList(fileItemService.selectList(fileItemSearch));
		return file;
	}
	
	@Override
	public void deleteFileItem(Long fileId) {
		FileItemSearch fileItemSearch = new FileItemSearch();
		fileItemSearch.setFileId(fileId);
		List<FileItem> fileItemList = fileItemService.selectList(fileItemSearch);
		for(FileItem fileItem : fileItemList) {
			fileItemService.delete(fileItem);
		}
	}

}
