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

import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcRebaseFailed;
import io.grpc.Status;

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

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

public class RebaseException extends AbstractGitException {

    public RebaseException(@Nonnull String message) {
        super(requireNonNull(message, "message"), FAILED_PRECONDITION);
    }

    public RebaseException(@Nonnull String message, @Nonnull Status status) {
        super(requireNonNull(message, "message"), status);
    }

    public RebaseException(@Nonnull String message, @Nullable Throwable cause) {
        super(requireNonNull(message, "message"), cause, FAILED_PRECONDITION);
    }

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