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.RpcNoSuchHookScript;

import javax.annotation.Nonnull;

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

public class HookScriptNotFoundException extends AbstractGitException {

    private final String id;

    public HookScriptNotFoundException(@Nonnull String id) {
        super("There is no hook script with ID '" + requireNonNull(id, "id") + "'", NOT_FOUND);

        this.id = id;
    }

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

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