package com.atlassian.stash.internal.comment.like;

import com.atlassian.bitbucket.comment.Comment;
import com.atlassian.bitbucket.comment.like.CommentLikeService;
import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.util.PageRequest;

import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Map;

/**
 * @since 3.5
 */
public interface InternalCommentLikeService extends CommentLikeService {

    /**
     * Return "liked by" information for requested {@code comments} mapped by comment ID. The returned map is guaranteed
     * to have an entry for each comment in the {@code commments} list.
     * <p>
     * The ordering of likers will be as in {@link #findByComment(Repository, Comment, PageRequest)}. The list of likers
     * may be truncated to an implementation-specific hard limit, with the {@code total} property providing the
     * actual count of users who liked the comment.
     * <p>
     * This method does not enforce any security checks, assuming that the clients have already established that the
     * calling user has sufficient permissions.
     *
     * @param comments list of comments to retrieve likes for
     * @return map of comment IDs to the {@link LikedBy like information}
     */
    @Nonnull
    Map<Long, LikedBy> findByComments(@Nonnull Iterable<Comment> comments);

    /**
     * Filters out non-existent comment likes.
     *
     * @param commentLikes a map of comment IDs to user IDs representing the likes
     * @return the {@code commentLikes} minus the non-existent entries
     * @since 3.7
     */
    @Nonnull
    Map<Long, Collection<Integer>> retainExisting(@Nonnull Map<Long, Collection<Integer>> commentLikes);
}
