//******** move the preProcessor from the core to the component ********//
function preProcessor(q, field, document, userId, logger) {
    logger.info("Start gbl-check-box preProcessor");
    let deferred = q.defer();

    let isProceed = true;
    if(typeof(document[field.name]) === "boolean"){
        isProceed = false;
    }
    // Commented this code because this is commented in the core changed(13630: do not delete null/empty field in preprocessor);
    //if(document[field.name] === "" && isProceed){
    //    delete document[field.name];
    //}

    if(document[field.name]){
        if(isProceed){
            if(!!document[field.name] && typeof(document[field.name]) === "string"){
                let saveValue = document[field.name];
                document[field.name] = document[field.name].toLowerCase();

                if(document[field.name] === "true" || document[field.name] === "false" ){
                    document[field.name] = JSON.parse(document[field.name]);
                }else{
                    let errMsg = field.componentName + " field named " + field.name + " has invalid value \"" + saveValue + "\"";
                    logger.error("Preprocessing Failure : " + errMsg);
                    return null;
                }
            }

            if(!document[field.name] || document[field.name] === undefined){
                let errMsg = field.componentName + " field named " + field.name + " has invalid value";
                deferred.reject(errMsg);
            }
        }
    }

    deferred.resolve(document);
    logger.info("End gbl-check-box preProcessor");
    return deferred.promise;
}
module.exports = preProcessor;
