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

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

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

import static com.atlassian.bitbucket.mesh.rpc.util.ByteStringUtils.nullToEmpty;

public class NoDefaultBranchException extends AbstractNotFoundException {

    private final String branchId;

    public NoDefaultBranchException(@Nullable String branchId) {
        super("The default branch does not exist");

        this.branchId = branchId;
    }

    @Nullable
    public String getBranchId() {
        return branchId;
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setNoDefaultBranch(RpcNoDefaultBranch.newBuilder()
                        .setBranchId(nullToEmpty(branchId)))
                .build();
    }
}
