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

import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcUnsupportedMergeStrategy;

import javax.annotation.Nonnull;
import java.util.List;

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

public class UnsupportedMergeStrategyException extends AbstractGitException {

    private final String strategyId;
    private final List<String> supportedStrategies;

    public UnsupportedMergeStrategyException(@Nonnull String strategyId, @Nonnull List<String> supportedStrategies) {
        super("Unsupported merge strategy: " + strategyId, INVALID_ARGUMENT);

        this.strategyId = requireNonNull(strategyId, "strategyId");
        this.supportedStrategies = requireNonNull(supportedStrategies, "supportedStrategies");
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setUnsupportedMergeStrategy(RpcUnsupportedMergeStrategy.newBuilder()
                        .addAllSupportedStrategies(supportedStrategies)
                        .setStrategyId(strategyId))
                .build();
    }
}
