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

import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcUnsupportedCommand;
import com.google.protobuf.ByteString;
import io.grpc.Status;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class UnsupportedCommandException extends AbstractGitException {

    private final String commandLine;

    public UnsupportedCommandException(@Nonnull String commandLine) {
        super("Unsupported command: " + commandLine, Status.INVALID_ARGUMENT);

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

    @Nonnull
    public String getCommandLine() {
        return commandLine;
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setUnsupportedCommand(RpcUnsupportedCommand.newBuilder()
                        .setCommandLine(ByteString.copyFromUtf8(commandLine)))
                .build();
    }
}
