package info.bukova.isspst.filters;

import info.bukova.isspst.BooleanUtils;
import info.bukova.isspst.DateTimeUtils;
import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.Requirement;
import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workgroup;

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

public class RequirementFilter implements Filter<Requirement>
{

	private Requirement condition;

	public RequirementFilter(Requirement cond)
	{
		this.condition = cond;
	}

	private static class RequirementMatcher extends TypeSafeMatcher<Requirement>
	{

		private Requirement condition;

		public RequirementMatcher(Requirement cond)
		{
			this.condition = cond;
		}

		@Override
		public void describeTo(Description desc)
		{
			desc.appendText("requirement matches");
		}

		@Override
		public boolean matchesSafely(Requirement item)
		{
			boolean foundNumser = StringUtils.isEqualForFilter(item.getNumser(), condition.getNumser());
			boolean foundReqDate = DateTimeUtils.isEqualByDateForFilter(item.getReqDate(), condition.getReqDate());
			boolean foundCenter = Workgroup.isEqualByWorkgroupForFilter(item.getCentre(), condition.getCentre());
			boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription());
			boolean foundDeliveryDate = DateTimeUtils.isEqualByDateForFilter(item.getDeliveryDate(), condition.getDeliveryDate());
			boolean foundUser = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy());
			boolean foundProject = BooleanUtils.isEqualByBooleanValue(item.getProject(), condition.getProject());
			return (foundNumser && foundReqDate && foundCenter && foundDescription && foundDeliveryDate && foundUser && foundProject);
		}

		@Factory
		public static Matcher<Requirement> matchBuilding(Requirement building)
		{
			return new RequirementMatcher(building);
		}
	}

	@Override
	public RequirementMatcher matcher()
	{
		return new RequirementMatcher(condition);
	}

	@Override
	public String queryString()
	{
		return "";
	}

}
