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

import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcLfsByteRangeNotSatisfiable;
import io.grpc.Status;

import javax.annotation.Nonnull;

public class LfsByteRangeNotSatisfiableException extends AbstractGitException {

    private final long end;
    private final long start;

    public LfsByteRangeNotSatisfiableException(long start, long end) {
        super("Range " + start + " - " + end + " not satisfiable", Status.OUT_OF_RANGE);

        this.end = end;
        this.start = start;
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setLfsByteRangeNotSatisfiable(RpcLfsByteRangeNotSatisfiable.newBuilder()
                        .setEnd(end)
                        .setStart(start))
                .build();
    }
}
