package info.bukova.isspst.filters;

import info.bukova.isspst.DateTimeUtils;
import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.SignedDocument;

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

public class SignedDocumentFilter implements Filter<SignedDocument>
{
	private SignedDocument condition;

	public SignedDocumentFilter(SignedDocument cond)
	{
		this.condition = cond;
	}

	private static class SignedDocumentMatcher extends TypeSafeMatcher<SignedDocument>
	{
		private SignedDocument condition;

		public SignedDocumentMatcher(SignedDocument cond)
		{
			this.condition = cond;
		}

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

		@Override
		public boolean matchesSafely(SignedDocument item)
		{
			boolean foundAgendaName = StringUtils.isEqualForFilter(item.getAgendaName(), condition.getAgendaName());
			boolean foundNumSer = StringUtils.isEqualForFilter(item.getNumser(), condition.getNumser());
			boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription());
			boolean foundSignDate = DateTimeUtils.isEqualByDateForFilter(item.getSignDate(), condition.getSignDate());
			return (foundAgendaName && foundNumSer && foundDescription && foundSignDate);
		}

		@Factory
		public static Matcher<SignedDocument> matchBuilding(SignedDocument item)
		{
			return new SignedDocumentMatcher(item);
		}
	}

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

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