package com.atlassian.stash.internal.web.repos;

import com.atlassian.bitbucket.repository.Ref;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;

import java.util.Objects;

class ViewRefMatcher extends TypeSafeDiagnosingMatcher<ViewRef> {

    static ViewRefMatcher ref(Ref ref) {
        return new ViewRefMatcher(ref.getId());
    }

    static ViewRefMatcher ref(String id) {
        return new ViewRefMatcher(id);
    }

    private final String id;

    private ViewRefMatcher(String id) {
        this.id = id;
    }

    @Override
    protected boolean matchesSafely(ViewRef item, Description mismatchDescription) {
        if (Objects.equals(item.getId(), id)) {
            return true;
        } else {
            mismatchDescription.appendText(item.getId());
            return false;
        }
    }

    @Override
    public void describeTo(Description description) {
        description.appendText(id);
    }
}
