package com.atlassian.bitbucket.mesh.repair;

import com.atlassian.bitbucket.mesh.AbstractStatusException;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcErrorUtils;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcRepositoryRepairAlreadyRunning;
import io.grpc.Metadata;
import io.grpc.Status;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class RepositoryRepairAlreadyRunningException extends AbstractStatusException {

    public RepositoryRepairAlreadyRunningException(@Nonnull String repositoryId) {
        super("Repair of " + requireNonNull(repositoryId, "repositoryId") + " is already running", Status.ABORTED);
    }

    @Override
    protected Metadata getTrailers() {
        return RpcErrorUtils.toMetadata(RpcError.newBuilder()
                .setRepositoryRepairAlreadyRunning(RpcRepositoryRepairAlreadyRunning.getDefaultInstance())
                .build());
    }
}
