/*
 * 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("adminPersonValidator")
public class AdminPersonValidator extends GenericValidator implements Validator {

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

        switch (component.getId()) {
            case "email":
                if (!"".equals(value.toString().trim())) {
                    emailValidator(value.toString());
                }
                break;
            case "firstName":
                notEmptyValidator(MIN_LENGTH_3_1, 3, value.toString(), "validator.first.name");
                break;
            case "secondName":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(MIN_LENGTH_3_1, 3, value.toString(), "validator.second.name");
                }
                break;
            case "lastName":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(MIN_LENGTH_3_1, 3, value.toString(), "validator.last.name");
                }
                break;
            case "middleName":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(MIN_LENGTH_3_1, 3, value.toString(), "validator.middle.name");
                }
                break;
            case "addressSearch":
                notEmptyValidator(MIN_LENGTH_3_1, 3, value.toString(), "validator.address.search");
                break;
            case "localNumber":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(NUMBER_MAX_LENGTH_12, 1, value.toString(), "validator.phone.local");
                }
                break;
            case "mobile":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(NUMBER_MAX_LENGTH_12, 1, value.toString(), "validator.phone.mobile");
                }
                break;
            case "rfc":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(RFC, 1, value.toString().toUpperCase(), "validator.rfc");
                }
                break;
            case "curp":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(CURP, 1, value.toString().toUpperCase(), "validator.curp");
                }
                break;
            case "payment":
                floatNumber(value.toString(), "validator.payment");
                break;
            case "license":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(3, value.toString().toUpperCase(), "validator.license");
                }
                break;
            case "ife":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(5, value.toString().toUpperCase(), "validator.ife");
                }
                break;
            case "password":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(5, value.toString().toUpperCase(), "validator.ife");
                }
                break;
            case "confirmPasswordPnlGrp":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(5, value.toString().toUpperCase(), "validator.ife");
                }
                break;
            case "phone1":
                notEmptyValidator(NUMBER_MAX_LENGTH_12, 1, value.toString().toUpperCase(), "validator.reference.phone");
                break;
            case "phone2":
                notEmptyValidator(NUMBER_MAX_LENGTH_12, 1, value.toString().toUpperCase(), "validator.reference.phone");
                break;
            case "completeName1":
                notEmptyValidator(MAX_LENGTH_50, 3, value.toString().toUpperCase(), "validator.reference.name");
                break;
            case "completeName2":
                notEmptyValidator(MAX_LENGTH_50, 3, value.toString().toUpperCase(), "validator.reference.name");
                break;
            case "blackListReason":
                if ("".equals(value.toString().trim())) {
                    errorSeverity(getBundlePropertyFile().getString("validator.black.list.reason"));
                } else if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(MIN_LENGTH_3, 3, value.toString(), "validator.valid.black.list.reason");
                }
                break;
           case "abreviacionProyecto":
                    notEmptyValidator(TEXT_MAX_LENGTH_4, 4, value.toString(), "La abreviatura debe de ser de máximo 4 caracteres");
               break;                
        }
    }

}
