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

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

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

public class HookScriptWriteFailedException extends AbstractGitException {

    private final String id;

    public HookScriptWriteFailedException(@Nonnull String id, @Nullable String message, @Nullable Throwable cause) {
        super(message, cause, INTERNAL);

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

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

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