package info.bukova.isspst.filters;

import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.MUnit;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class MUnitFilter implements Filter<MUnit> {
	
	private MUnit condMUnit;
	
	public MUnitFilter(MUnit condMUnit) {
		this.condMUnit = condMUnit;
	}

	private static class MUnitMatcher extends TypeSafeMatcher<MUnit> {

		private MUnit condMUnit;
		
		public MUnitMatcher(MUnit cond) {
			this.condMUnit = cond;
		}
		
		@Override
		public void describeTo(Description desc) {
			desc.appendText("munits matches");
		}

		@Override
		public boolean matchesSafely(MUnit item)
		{
			boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condMUnit.getName());
			boolean descriptionIsEqual = StringUtils.isEqualForFilter(item.getDescription(), condMUnit.getDescription());
			return (nameIsEqual && descriptionIsEqual);
		}
		
		@Factory
		public static Matcher<MUnit> matchMUnit(MUnit munit) {
			return new MUnitMatcher(munit);
		}
	}
	
	@Override
	public MUnitMatcher matcher() {
		return new MUnitMatcher(condMUnit);
	}

	@Override
	public String queryString() {
		// TODO query string
		return "";
	}

}
