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

import com.atlassian.bitbucket.mesh.AbstractStatusException;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitErrorUtils;
import io.grpc.Metadata;
import io.grpc.Status;

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

public abstract class AbstractGitException extends AbstractStatusException {

    public AbstractGitException(@Nullable String message, @Nonnull Status status) {
        super(message, status);
    }

    public AbstractGitException(@Nullable String message, @Nullable Throwable cause, @Nonnull Status status) {
        super(message, cause, status);
    }

    public AbstractGitException(@Nullable Throwable cause, @Nonnull Status status) {
        super(cause, status);
    }

    @Nonnull
    public abstract RpcGitError toError();

    @Nonnull
    @Override
    protected Metadata getTrailers() {
        return RpcGitErrorUtils.toMetadata(toError());
    }
}
