package persistence.link;

import abstraction.PersistenceAdapter;
import link.Link;
import persistence.GenericDAO;

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

public class CSVLinkPersistenceAdapter implements PersistenceAdapter<Link> {

	private final GenericDAO<LinkEntity> linkDAO;

	public CSVLinkPersistenceAdapter(GenericDAO<LinkEntity> linkDAO) {
		this.linkDAO = linkDAO;
	}

	@Override
	public Set<Link> getAll() {
		return linkDAO.getAll().stream().map(LinkEntity::toLink).collect(Collectors.toSet());
	}

	@Override
	public void add(Link link) {
		linkDAO.add(new LinkEntity(link));
	}

	@Override
	public void remove(Link link) {
		linkDAO.remove(new LinkEntity(link));
	}
}
