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

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

import javax.annotation.Nonnull;

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

public class RemoteAuthorizationException extends AbstractGitException {

    private final String url;

    public RemoteAuthorizationException(@Nonnull String message, @Nonnull String url) {
        super(requireNonNull(message, "message"), PERMISSION_DENIED);

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

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

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