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

import com.atlassian.bitbucket.comment.CommentAction;
import com.atlassian.bitbucket.comment.DiffCommentAnchor;
import com.atlassian.bitbucket.comment.commit.AddCommitFileCommentRequest;
import com.atlassian.bitbucket.comment.commit.AddCommitLineCommentRequest;
import com.atlassian.bitbucket.comment.pull.AddPullRequestFileCommentRequest;
import com.atlassian.bitbucket.comment.pull.AddPullRequestLineCommentRequest;
import com.atlassian.stash.internal.comment.InternalComment;
import com.atlassian.stash.internal.comment.InternalCommentHelper;
import com.atlassian.stash.internal.pull.InternalPullRequest;
import com.atlassian.stash.internal.pull.InternalPullRequestDiffCommentAnchor;
import com.atlassian.stash.internal.pull.PullRequestAnchorSearchCriteria;

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

/**
 * @since 1.3
 */
public interface InternalPullRequestCommentHelper
        extends InternalCommentHelper<InternalPullRequest, InternalPullRequestDiffCommentAnchor> {

    /**
     * Add comment activity to the pull request
     * @param pullRequest the pull request to which the activity should be added
     * @param comment the comment the activity relates to
     * @param commentAction the action performed
     * @since 4.7
     */
    void addCommentActivity(@Nonnull InternalPullRequest pullRequest, @Nonnull InternalComment comment,
                            @Nonnull CommentAction commentAction);

    @Nonnull
    InternalPullRequestDiffCommentAnchor createLineAnchor(@Nonnull InternalPullRequest pullRequest,
                                                          @Nonnull InternalComment comment,
                                                          @Nonnull AddCommitLineCommentRequest request);

    @Nonnull
    InternalComment createLineComment(@Nonnull AddPullRequestLineCommentRequest request);

    @Nonnull
    InternalPullRequestDiffCommentAnchor createFileAnchor(@Nonnull InternalPullRequest pullRequest,
                                                          @Nonnull InternalComment comment,
                                                          @Nonnull AddCommitFileCommentRequest request);

    @Nonnull
    InternalComment createFileComment(@Nonnull AddPullRequestFileCommentRequest request);

    /**
     * Search for all {@link InternalPullRequestDiffCommentAnchor anchors} which match the search criteria.
     * @param searchCriteria the criteria describing the anchors to match.
     * @param enrich whether the anchors must be enriched.
     * @return the anchors which match the provided search request.
     * @since 4.8
     */
    @Nonnull
    List<InternalPullRequestDiffCommentAnchor> findDiffAnchors(@Nonnull PullRequestAnchorSearchCriteria searchCriteria,
                                                               boolean enrich);

    void maybeUpdateComments(@Nonnull InternalPullRequest pullRequest);

    void updateAnchors(@Nonnull List<InternalPullRequestDiffCommentAnchor> anchors);

    void updateComments(@Nonnull InternalPullRequest pullRequest, @Nonnull String previousFromHash,
                        @Nonnull String previousToHash);
}
