package info.bukova.isspst.validators;

import info.bukova.isspst.StringUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.bind.Property;
import org.zkoss.bind.ValidationContext;

public class UserPasswordDuplValidator extends BaseValidator
{
	private final static Logger log = LoggerFactory.getLogger(UserPasswordDuplValidator.class.getName());

	@Override
	protected Logger getLogger()
	{
		return log;
	}

	@Override
	public void validate(ValidationContext ctx)
	{
		return;
	}
	
	public void aaa(ValidationContext ctx)
	{
		Object argOrig = ctx.getBindContext().getValidatorArg("orig");

		if (argOrig == null)
		{
			this.addErrorMsg(ctx, StringUtils.localize("NullPointerErr"));
			return;
		}

		if (!(argOrig instanceof String))
		{
			this.addErrorMsg(ctx, StringUtils.localize("DataTypeErr"));
			return;
		}

		String propertyNameOrig = (String) argOrig;

		Property propertyOrig = ctx.getProperties(propertyNameOrig)[0];
		String passwordOrig = (String) propertyOrig.getValue();

		if (passwordOrig == null)
		{
			passwordOrig = "";
		}

		Property propertyDupl = ctx.getProperty();
		String passwordDupl = (String) propertyDupl.getValue();

		if (passwordDupl == null)
		{
			passwordDupl = "";
		}

		if (!passwordOrig.equals(passwordDupl))
		{
			this.addErrorMsg(ctx, StringUtils.localize("UserPasswordsAreNotSame"));
		}
	}
}
