package info.bukova.isspst.validators;

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

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

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

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

	@Override
	public void validate(ValidationContext ctx)
	{
		Property propertyCentre = ctx.getProperties("centre")[0];

		if (propertyCentre != null) {
			Workgroup workgroup = (Workgroup) propertyCentre.getValue();

			if (workgroup == null) {
				this.errorMsg(ctx, StringUtils.localize("RequirementCenterIsEmpty"), "idReqCenter");
				return;
			}
		}

		Property propertyDescription = ctx.getProperties("description")[0];

		if (propertyDescription != null) {
			String description = (String) propertyDescription.getValue();

			if (StringUtils.isNullOrTrimmedEmpty(description)) {
				this.errorMsg(ctx, StringUtils.localize("ErrMaterialOrServiceDescription"), "idDescription");
				return;
			}
		}
	}
}
