package com.atlassian.bitbucket.hamcrest;

import com.atlassian.bitbucket.util.PageRequest;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class PageRequestMatcher extends TypeSafeMatcher<PageRequest> {

    @Factory
    public static Matcher<PageRequest> pageRequest(int limit) {
        return new PageRequestMatcher(limit);
    }

    @Factory
    public static Matcher<PageRequest> pageRequest(int start, int limit) {
        return new PageRequestMatcher(start, limit);
    }

    private final int limit;
    private final int start;

    public PageRequestMatcher(int limit) {
        this(0, limit);
    }

    public PageRequestMatcher(int start, int limit) {
        this.start = start;
        this.limit = limit;
    }

    @Override
    public void describeTo(Description description) {
        description.appendText("A page request with start at ")
                .appendValue(start)
                .appendText(" and limit of ")
                .appendValue(limit);
    }

    @Override
    protected boolean matchesSafely(PageRequest parameter) {
        return start == parameter.getStart() &&
                limit == parameter.getLimit();
    }

}
