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

import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcNoSuchObject;
import com.google.protobuf.ByteString;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class ObjectNotFoundException extends AbstractNotFoundException {

    private final String objectId;

    public ObjectNotFoundException(@Nonnull String objectId) {
        super("No such object: " + objectId);

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

    @Nonnull
    public String getObjectId() {
        return objectId;
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setNoSuchObject(RpcNoSuchObject.newBuilder()
                        .setObjectId(ByteString.copyFromUtf8(objectId)))
                .build();
    }
}
