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

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

import javax.annotation.Nonnull;

import static com.atlassian.bitbucket.mesh.rpc.v1.RpcInvalidRefName.Reason.TOO_LONG;

public class RefNameTooLongException extends InvalidRefNameException {

    private final int maxLength;

    public RefNameTooLongException(String refName, int maxLength) {
        super(TOO_LONG, refName);

        this.maxLength = maxLength;
    }

    public int getMaxLength() {
        return maxLength;
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setInvalidRefName(getError()
                        .setMaxLength(maxLength))
                .build();
    }
}
