package com.atlassian.stash.internal.pull;

import com.atlassian.bitbucket.pull.PullRequestCommentAnchorDiffType;
import com.atlassian.stash.internal.comment.AbstractDiffCommentAnchorSearchCriteria;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Optional;

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

/**
 * @since 4.8
 */
public class PullRequestAnchorSearchCriteria extends AbstractDiffCommentAnchorSearchCriteria {

    private final PullRequestCommentAnchorDiffType diffType;
    private final InternalPullRequest pullRequest;

    private PullRequestAnchorSearchCriteria(@Nonnull Builder builder) {
        super(builder);

        diffType = builder.diffType;
        pullRequest = builder.pullRequest;
    }

    @Nonnull
    public Optional<PullRequestCommentAnchorDiffType> getDiffType() {
        return ofNullable(diffType);
    }

    @Nonnull
    public InternalPullRequest getPullRequest() {
        return pullRequest;
    }

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

        private final InternalPullRequest pullRequest;

        private PullRequestCommentAnchorDiffType diffType;

        public Builder(@Nonnull InternalPullRequest value) {
            pullRequest = requireNonNull(value, "pullRequest");
        }

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

        @Nonnull
        public Builder diffType(@Nullable PullRequestCommentAnchorDiffType value) {
            diffType = value;
            return this;
        }

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