package com.atlassian.bitbucket.mesh.git.hook.script;

import com.atlassian.bitbucket.mesh.git.exception.AbstractGitException;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcInvalidHookScriptId;

import javax.annotation.Nonnull;

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

public class InvalidHookScriptIdException extends AbstractGitException {

    private final String id;

    public InvalidHookScriptIdException(@Nonnull String id) {
        super(requireNonNull(id, "id") + " is not a valid hook script ID", INVALID_ARGUMENT);

        this.id = id;
    }

    @Nonnull
    public String getId() {
        return id;
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setInvalidHookScriptId(RpcInvalidHookScriptId.newBuilder().setHookScriptId(id))
                .build();
    }
}
