package com.atlassian.bitbucket.comment;

import com.atlassian.bitbucket.content.DiffFileType;
import com.atlassian.bitbucket.content.DiffSegmentType;

import javax.annotation.Nonnull;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Request to create or update a {@link DiffCommentAnchor#isLineComment() diff comment}.
 *
 * @deprecated in 4.7 for removal in 5.0.
 * Use one of {@link com.atlassian.bitbucket.comment.pull.AddPullRequestLineCommentRequest} or
 * {@link com.atlassian.bitbucket.comment.commit.AddCommitLineCommentRequest} instead
 */
@Deprecated
public class AddDiffCommentRequest extends AbstractAddCommentRequest {

    private final DiffFileType fileType;
    private final int line;
    private final DiffSegmentType lineType;

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

        this.fileType = checkNotNull(builder.fileType, "fileType");
        this.line = builder.line;
        this.lineType = checkNotNull(builder.lineType, "lineType");
    }

    /**
     * @return the type of the file the comments is attached to
     */
    @Nonnull
    public DiffFileType getFileType() {
        return fileType;
    }

    /**
     * @return the line number in the diff
     */
    public int getLine() {
        return line;
    }

    /**
     * @return the type of the diff segment the commented line represents
     */
    @Nonnull
    public DiffSegmentType getLineType() {
        return lineType;
    }

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

        private int line = DiffCommentAnchor.NO_LINE;
        private DiffSegmentType lineType;
        private DiffFileType fileType;

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

        @Nonnull
        public Builder fileType(@Nonnull DiffFileType value) {
            fileType = checkNotNull(value, "fileType");

            return this;
        }

        @Nonnull
        public Builder line(int value) {
            checkArgument(line >= DiffCommentAnchor.NO_LINE, "Line must be >= %s (Rejected: %s)", DiffCommentAnchor.NO_LINE, value);
            line = value;

            return this;
        }

        @Nonnull
        public Builder lineType(@Nonnull DiffSegmentType value) {
            lineType = checkNotNull(value, "lineType");

            return this;
        }

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