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

import com.atlassian.bitbucket.mesh.git.exception.AbstractGitException;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcNoSuchWorkTree;
import io.grpc.Status;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class WorkTreeNotFoundException extends AbstractGitException {

    private final String id;

    public WorkTreeNotFoundException(@Nonnull String id) {
        super("Work tree not found", Status.NOT_FOUND);
        this.id = requireNonNull(id, "id");
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setNoSuchWorkTree(RpcNoSuchWorkTree.newBuilder()
                        .setId(id))
                .build();
    }
}
