package com.atlassian.bitbucket.mesh.git.exception;

import com.atlassian.bitbucket.mesh.git.pull.PullRequest;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcDeletePullRequestFailed;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;

import javax.annotation.Nonnull;

import static io.grpc.Status.INTERNAL;
import static java.util.Objects.requireNonNull;

public class DeletePullRequestFailedException extends AbstractGitException {

    private final PullRequest pullRequest;

    public DeletePullRequestFailedException(@Nonnull PullRequest pullRequest) {
        super("Failed to delete pull request: " + pullRequest, null, INTERNAL);

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

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

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setDeletePullRequestFailed(RpcDeletePullRequestFailed.getDefaultInstance())
                .build();
    }
}
