package info.bukova.isspst.filters;

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

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

public class ServiceItemFilter implements Filter<ServiceItem> {
	
	private ServiceItem condServiceItem;
	
	public ServiceItemFilter(ServiceItem condServiceItem) {
		this.condServiceItem = condServiceItem;
	}

	private static class ServiceItemMatcher extends TypeSafeMatcher<ServiceItem> {

		private ServiceItem condServiceItem;
		
		public ServiceItemMatcher(ServiceItem cond) {
			this.condServiceItem = cond;
		}
		
		@Override
		public void describeTo(Description desc) {
			desc.appendText("material matches");
		}

		@Override
		public boolean matchesSafely(ServiceItem item)
		{
			boolean codeIsEqual = StringUtils.isEqualForFilter(item.getCode(), condServiceItem.getCode());
			boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condServiceItem.getName());
			boolean descriptionIsEqual = StringUtils.isEqualForFilter(item.getDescription(), condServiceItem.getDescription());
			return (codeIsEqual && nameIsEqual && descriptionIsEqual);
		}
		
		@Factory
		public static Matcher<ServiceItem> matchBuilding(ServiceItem material) {
			return new ServiceItemMatcher(material);
		}
	}
	
	@Override
	public ServiceItemMatcher matcher() {
		return new ServiceItemMatcher(condServiceItem);
	}

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

}
