/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arrebol.taxiservicios.validators;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author Picasso
 */
@FacesValidator("systemUserValidator")
public class SystemUserValidator extends GenericValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        loadBundlePropertyFile();

        switch (component.getId()) {
            case "username":
                notEmptyValidator(MIN_LENGTH_3, 3, value.toString(), "validator.username");
                existUser(value.toString(), "validator.username.exist");
                break;
            case "firstName":
                notEmptyValidator(MIN_LENGTH_3, 3, value.toString(), "validator.first.name");
                break;
            case "secondName":
                notEmptyValidator(MIN_LENGTH_3, 3, value.toString(), "validator.second.name");
                break;
            case "lastName":
                notEmptyValidator(MIN_LENGTH_3, 3, value.toString(), "validator.last.name");
                break;
            case "middleName":
                notEmptyValidator(MIN_LENGTH_3, 3, value.toString(), "validator.middle.name");
                break;
            case "addressSearch":
                notEmptyValidator(MIN_LENGTH_3, 3, value.toString(), "validator.address.search");
        }
    }

}
