package sk.yonban.core.aspectchanges;

import org.springframework.validation.Errors;

import sk.yonban.model.command.PouzivatelInfoCommand;
import sk.yonban.validation.BaseValidator;

public class PouzivatelInfoValidator extends BaseValidator {

	private static final String ERROR_POUZIVATEL_INFO_TELEFON_ERROR = "error.pouzivatelInfo.telefonError";

	public boolean supports(Class commandClass) {
		return PouzivatelInfoCommand.class.equals(commandClass);
	}

	public void validate(Object cmd, Errors errors) {
		PouzivatelInfoCommand command = (PouzivatelInfoCommand) cmd;
		try {
			if (command == null || !validatePhoneNumber(command.getTelefon())) {
				errors.rejectValue("telefon", ERROR_POUZIVATEL_INFO_TELEFON_ERROR);
			}
		} catch (Exception e) {
		}
	}

	private boolean validatePhoneNumber(String telefon) throws Exception {
		return (telefon.length() > 8); 
	}
}
