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

import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcRemoteAuthenticationFailed;

import javax.annotation.Nonnull;

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

public class RemoteAuthenticationException extends AbstractGitException {

    private final String url;

    public RemoteAuthenticationException(@Nonnull String message, @Nonnull String url) {
        super(requireNonNull(message, "message"), UNAUTHENTICATED);

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

    @Nonnull
    public String getUrl() {
        return url;
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setRemoteAuthenticationFailed(RpcRemoteAuthenticationFailed.newBuilder()
                        .setUrl(url))
                .build();
    }
}
