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

import com.atlassian.stash.internal.commit.InternalCommitDiscussion;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import java.util.Optional;

import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;

/**
 * Groups the different parameters which can be used to filter a commit discussion
 * {@link com.atlassian.stash.internal.commit.InternalCommitDiscussionCommentAnchor anchor} search
 *
 * @since 4.7
 */
public class CommitDiscussionCommentAnchorSearchRequest {

    private final InternalCommitDiscussion discussion;
    private final String parentId;
    private final String path;
    private final Long pullRequestScopeId;

    private CommitDiscussionCommentAnchorSearchRequest(Builder builder) {
        discussion = builder.discussion;
        parentId = builder.parentId;
        path = builder.path;
        pullRequestScopeId = builder.pullRequestScopeId;
    }

    @Nonnull
    public InternalCommitDiscussion getDiscussion() {
        return discussion;
    }

    @Nonnull
    public Optional<String> getParentId() {
        return ofNullable(parentId);
    }

    @Nonnull
    public Optional<String> getPath() {
        return ofNullable(path);
    }

    @Nonnull
    public Optional<Long> getPullRequestScopeId() {
        return ofNullable(pullRequestScopeId);
    }

    public static class Builder {

        private final InternalCommitDiscussion discussion;

        private String parentId;
        private String path;
        private Long pullRequestScopeId;

        public Builder(@Nonnull InternalCommitDiscussion discussion) {
            this.discussion = requireNonNull(discussion, "discussion");
        }

        @Nonnull
        public CommitDiscussionCommentAnchorSearchRequest build() {
            return new CommitDiscussionCommentAnchorSearchRequest(this);
        }

        @Nonnull
        public Builder path(@Nullable String value) {
            path = value;
            return this;
        }

        @Nonnull
        public Builder parentId(@Nullable String value) {
            parentId = value;
            return this;
        }

        @Nonnull
        public Builder pullRequestScopeId(@Nullable Long value) {
            pullRequestScopeId = value;
            return this;
        }
    }
}
