package com.atlassian.bitbucket.internal.importer.github;

import com.atlassian.bitbucket.util.PageRequest;
import com.atlassian.bitbucket.util.UrlUtils;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public abstract class AbstractPageUrlBuilder<T> extends AbstractUrlBuilder<T> {

    private final int limit;
    private final int start;

    protected AbstractPageUrlBuilder(@Nonnull String defaultBaseUrl, @Nonnull PageRequest pageRequest) {
        super(defaultBaseUrl);
        requireNonNull(pageRequest, "pageRequest");

        limit = pageRequest.getLimit();
        start = pageRequest.getStart();
    }

    @Nonnull
    protected String pageParameters() {
        return UrlUtils.buildQueryParams("per_page", limit, "page", (start / limit) + 1);
    }
}