package info.bukova.isspst.filters;

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

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

public class UserFilter implements Filter<User> {
	
	private User condUser;
	
	public UserFilter(User condition) {
		this.condUser = condition;
	}
	
	private static class UserMatcher extends TypeSafeMatcher<User> {

		private User condUser;
		
		public UserMatcher(User condition) {
			this.condUser = condition;
		}
		
		@Override
		public void describeTo(Description description) {
			description.appendText("user matcher");
		}

		@Override
		public boolean matchesSafely(User item)
		{
			boolean userNameIsEqual = StringUtils.isEqualForFilter(item.getUsername(), condUser.getUsername());
			boolean firstNameIsEqual = StringUtils.isEqualForFilter(item.getFirstName(), condUser.getFirstName());
			boolean lastNameIsEqual = StringUtils.isEqualForFilter(item.getLastName(), condUser.getLastName());
			boolean personalNumberIsEqual = StringUtils.isEqualForFilter(item.getPersonalNumber(), condUser.getPersonalNumber());
			return (userNameIsEqual && firstNameIsEqual && lastNameIsEqual && personalNumberIsEqual);
		}
		
		@Factory
		public UserMatcher matchUser(User cond) {
			return new UserMatcher(cond);
		}
		
	}

	@Override
	public TypeSafeMatcher<User> matcher() {
		return new UserMatcher(condUser);
	}

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

}
