package info.bukova.isspst.filters;

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

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

public class BuildingFilter implements Filter<Building> {
	
	private Building condBuilding;
	
	public BuildingFilter(Building condBuilding) {
		this.condBuilding = condBuilding;
	}

	private static class BuildingMatcher extends TypeSafeMatcher<Building> {

		private Building condBuilding;
		
		public BuildingMatcher(Building cond) {
			this.condBuilding = cond;
		}
		
		@Override
		public void describeTo(Description desc) {
			desc.appendText("buildings matches");
		}

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

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

}
