package dev.dinauer.maven.app;

import dev.dinauer.maven.maven.core.GroupId;
import dev.dinauer.maven.shared.UserReferencing;
import dev.dinauer.maven.user.User;
import dev.dinauer.maven.user.UserClient;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.rest.client.inject.RestClient;

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

@ApplicationScoped
public class GroupMapper
{
    @Inject
    ArtifactMapper artifactMapper;

    @RestClient
    UserClient userClient;

    public List<GroupDTO> map(List<GroupId> input)
    {
        return input.stream().map(group -> this.map(group, userClient.get(UserReferencing.collect(input)))).toList();
    }

    public GroupDTO map(GroupId input, Map<String, User> users)
    {
        return new GroupDTO(input.getId(), input.getGroupId(), artifactMapper.map(input.getArtifacts(), users));
    }
}
