package persistence.category;

import abstraction.PersistenceAdapter;
import category.Category;
import persistence.GenericDAO;

import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

public class CSVCategoryPersistenceAdapter implements PersistenceAdapter<Category> {

	static Function<String[], CategoryEntity> constuctor = CategoryEntity::new;
	private final GenericDAO<CategoryEntity> categoryDAO;

	public CSVCategoryPersistenceAdapter(GenericDAO<CategoryEntity> categoryDAO) {
		this.categoryDAO = categoryDAO;
	}

	@Override
	public Set<Category> getAll() {
		return categoryDAO.getAll().stream().map(CategoryEntity::toCategory).collect(Collectors.toSet());
	}

	@Override
	public void remove(Category category) {
		categoryDAO.remove(new CategoryEntity(category));
	}

	@Override
	public void add(Category category) {
		categoryDAO.add(new CategoryEntity(category));
	}
}
