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

import com.atlassian.bitbucket.comment.DiffCommentAnchor;
import com.atlassian.bitbucket.comment.commit.AddCommitLineCommentRequest;
import com.atlassian.bitbucket.comment.commit.AddCommitFileCommentRequest;
import com.atlassian.stash.internal.comment.CommentCounts;
import com.atlassian.stash.internal.comment.InternalComment;
import com.atlassian.stash.internal.comment.InternalCommentHelper;
import com.atlassian.stash.internal.commit.InternalCommitDiscussion;
import com.atlassian.stash.internal.commit.InternalCommitDiscussionCommentAnchor;
import com.atlassian.stash.internal.content.InternalChangeLocation;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;

/**
 * @since 2.11
 */
public interface InternalCommitDiscussionCommentHelper
        extends InternalCommentHelper<InternalCommitDiscussion, InternalCommitDiscussionCommentAnchor> {

    @Nonnull
    InternalComment createLineComment(@Nonnull InternalCommitDiscussion discussion,
                                      @Nonnull AddCommitLineCommentRequest request);

    @Nonnull
    InternalComment createFileComment(@Nonnull InternalCommitDiscussion discussion,
                                      @Nonnull AddCommitFileCommentRequest request);

    @Nonnull
    List<DiffCommentAnchor> findDiffAnchors(@Nonnull CommitDiscussionCommentAnchorSearchRequest request,
                                            boolean enrich);

    @Nullable
    InternalCommitDiscussionCommentAnchor getAnchorByComment(@Nonnull InternalCommitDiscussion discussion,
                                                             long commentId);

    /**
     * Retrieves comment counts for all paths in the specified commit discussion. If a pull request ID is provided
     * only comments associated with the identified pull request will be counted. If a pull request ID is not provided
     * only comments which are not associated with any pull request will be counted. The counts are mapped by
     * {@link InternalChangeLocation} to simplify looking them up by both path and srcPath (if available).
     *
     * @param discussion the commit discussion to retrieve comment counts for
     * @param pullRequestId the ID for a pull request the comments should be associated with
     * @return a map containing zero or more counts mapped by location
     */
    @Nonnull
    Map<InternalChangeLocation, CommentCounts> countsByLocation(@Nonnull InternalCommitDiscussion discussion,
                                                                @Nullable Long pullRequestId);
}
