package persistence.customTags;

import abstraction.PersistenceAdapter;
import persistence.GenericDAO;
import tag.matcherImplementations.CustomTagMatcher;

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

public class CSVCustomTagMatcherPersistenceAdapter implements PersistenceAdapter<CustomTagMatcher> {

	private final GenericDAO<CustomTagMatcherEntity> customTagMatcherDAO;

	public CSVCustomTagMatcherPersistenceAdapter(GenericDAO<CustomTagMatcherEntity> customTagMatcherDAO) {
		this.customTagMatcherDAO = customTagMatcherDAO;
	}

	@Override
	public Set<CustomTagMatcher> getAll() {
		return customTagMatcherDAO
				.getAll()
				.stream()
				.map(CustomTagMatcherEntity::toCustomTagMatcher)
				.collect(Collectors.toSet());
	}

	@Override
	public void add(CustomTagMatcher value) {
		customTagMatcherDAO.add(new CustomTagMatcherEntity(value));
	}

	@Override
	public void remove(CustomTagMatcher value) {
		customTagMatcherDAO.remove(new CustomTagMatcherEntity(value));
	}
}
