package cli.link;

import category.CategoryName;
import link.LinkDto;
import link.LinkUrl;
import link.LinkUseCase;
import tag.TagName;
import user.Username;

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

public class LinkCliAdapter {

    private final LinkUseCase linkUseCase;

    public LinkCliAdapter(LinkUseCase linkUseCase) {
        this.linkUseCase = linkUseCase;
    }

    public void addLink(String url, Set<String> categoryNames, String creator) {
        linkUseCase.addLink(new LinkUrl(url),
                categoryNames.stream().map(CategoryName::new).collect(Collectors.toSet()),
                new Username(creator));
    }

    public Set<String> getLinks() {
        return linkUseCase.getLinks().stream().map(LinkDto::toString).collect(Collectors.toSet());
    }

    public Set<String> getLinksForCategory(String categoryName) {
        return linkUseCase.getLinksForCategory(new CategoryName(categoryName)).stream().map(LinkDto::toString).collect(Collectors.toSet());
    }

    public Set<String> getLinksForTag(String tagName) {
        return linkUseCase.getLinksForTag(new TagName(tagName)).stream().map(LinkDto::toString).collect(Collectors.toSet());
    }

    public Set<String> getLinksForUser(String userName) {
        return linkUseCase.getLinksForUser(new Username(userName)).stream().map(LinkDto::toString).collect(Collectors.toSet());
    }

    public List<String> groupByHosts() {
        return linkUseCase.groupByHosts().stream().map(LinkDto::toString).collect(Collectors.toList());
    }
}
