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

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

        switch (component.getId()) {
            case "year":
                if (null != value) {
                    notEmptyValidator(NUMBER_MAX_LENGTH_4, 4, value.toString().toUpperCase(), "validator.year");
                }
                break;
            case "placa":
                notEmptyValidator(3, value.toString().toUpperCase(), "validator.placa");
                break;
            case "economicNumber":
                notEmptyValidator(3, value.toString().toUpperCase(), "validator.economic.number");
                break;
            case "insuranceNumber":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(3, value.toString().toUpperCase(), "validator.insurance.number");
                }
                break;
            case "motorNmumber":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(3, value.toString().toUpperCase(), "validator.motor.number");
                }
                break;
            case "serialNumber":
                if (!"".equals(value.toString().trim())) {
                    notEmptyValidator(3, value.toString().toUpperCase(), "validator.serial.number");
                }
                break;
            case "payDay":
                doubleNumber(value, "validator.pay.day");                
                break;
            case "paySaving":
                doubleNumber(value, "validator.pay.saving");
                break;
            case "payAccident":
                doubleNumber(value, "validator.pay.accident");
                break;
        }
    }

}
