package com.atlassian.bitbucket.comment.pull;

import com.atlassian.bitbucket.comment.AbstractAddLineCommentRequest;
import com.atlassian.bitbucket.pull.PullRequest;
import com.atlassian.bitbucket.pull.PullRequestDiffCommentAnchor;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

/**
 * Request to create a {@link PullRequestDiffCommentAnchor#isLineComment() line comment}.
 *
 * @since 4.7
 */
public class AddPullRequestLineCommentRequest extends AbstractAddLineCommentRequest {

    private final PullRequest pullRequest;

    private AddPullRequestLineCommentRequest(Builder builder) {
        super(builder);

        pullRequest = requireNonNull(builder.pullRequest, "pullRequest");
    }

    /**
     * @return the pull request on which the comment should be added
     */
    public PullRequest getPullRequest() {
        return pullRequest;
    }

    public static class Builder extends AbstractBuilder<Builder, AddPullRequestLineCommentRequest> {

        private final PullRequest pullRequest;

        public Builder(@Nonnull PullRequest pullRequest) {
            this.pullRequest = pullRequest;
        }

        public Builder(@Nonnull AddPullRequestLineCommentRequest request) {
            super(request);

            pullRequest = request.pullRequest;
        }

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

        @Nonnull
        @Override
        protected Builder self() {
            return this;
        }
    }
}
