package info.bukova.isspst.filters;

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

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

public class AddressFilter implements Filter<Address> {
	
	private Address condAddr;
	
	public AddressFilter(Address condAddr) {
		this.condAddr = condAddr;
	}

	private static class AddrMatcher extends TypeSafeMatcher<Address> {

		private Address condAddress;
		
		public AddrMatcher(Address cond) {
			this.condAddress = cond;
		}
		
		@Override
		public void describeTo(Description desc) {
			desc.appendText("address matches");
		}

		@Override
		public boolean matchesSafely(Address item)
		{
			boolean companyIsEqual = StringUtils.isEqualForFilter(item.getCompany(), condAddress.getCompany());
			boolean cityIsEqual = StringUtils.isEqualForFilter(item.getCity(), condAddress.getCity());
			boolean contactNameIsEqual = StringUtils.isEqualForFilter(item.getContactName(), condAddress.getContactName());
			boolean streetIsEqual = StringUtils.isEqualForFilter(item.getStreet(), condAddress.getStreet());
			boolean icIsEqual = StringUtils.isIcEqualForFilter(item.getIc(), condAddress.getIc());
			boolean houseNumberIsEqual = StringUtils.isEqualForFilter(item.getHouseNumber(), condAddress.getHouseNumber());
			return (companyIsEqual && cityIsEqual && contactNameIsEqual && streetIsEqual && icIsEqual && houseNumberIsEqual);
		}
		
		@Factory
		public static Matcher<Address> matchAddr(Address addr) {
			return new AddrMatcher(addr);
		}
	}
	
	@Override
	public AddrMatcher matcher() {
		return new AddrMatcher(condAddr);
	}

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

}
