package info.bukova.isspst.filters;

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

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

public class WorkgroupFilter implements Filter<Workgroup> {
	
	private Workgroup condWorkgroup;
	
	public WorkgroupFilter(Workgroup condWorkgroup) {
		this.condWorkgroup = condWorkgroup;
	}

	private static class WorkgroupMatcher extends TypeSafeMatcher<Workgroup> {

		private Workgroup condWorkgroup;
		
		public WorkgroupMatcher(Workgroup cond) {
			this.condWorkgroup = cond;
		}
		
		@Override
		public void describeTo(Description desc) {
			desc.appendText("material matches");
		}

		@Override
		public boolean matchesSafely(Workgroup item)
		{
			boolean codeIsEqual = StringUtils.isEqualForFilter(item.getCode(), condWorkgroup.getCode());
			boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condWorkgroup.getName());
			boolean centerIsEqual = (item.isCentre() == condWorkgroup.isCentre());
			return (codeIsEqual && nameIsEqual && centerIsEqual);
		}
		
		@Factory
		public static Matcher<Workgroup> matchBuilding(Workgroup material) {
			return new WorkgroupMatcher(material);
		}
	}
	
	@Override
	public WorkgroupMatcher matcher() {
		return new WorkgroupMatcher(condWorkgroup);
	}

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

}
