class ClientProcessorForJava {

    public Boolean processField(org.smartregister.domain.jsonmapping.Field field, Event event, Client client) {
        try {
            if (field == null) {
                return false;
            }

            // keep checking if the event data matches the values expected by each rule, break the
            // moment the rule fails
            String dataSegment = null;
            String fieldName = field.field;
            String fieldValue = field.field_value;
            String responseKey = null;

            if (fieldName != null && fieldName.contains(".")) {
                String fieldNameArray[] = fieldName.split("\\.");
                dataSegment = fieldNameArray[0];
                fieldName = fieldNameArray[1];
                String concept = field.concept;

                if (concept != null) {
                    fieldValue = concept;
                    responseKey = VALUES_KEY;
                }
            }

            List<String> createsCase = field.creates_case;
            List<String> closesCase = field.closes_case;

            // some fields are in the main doc e.g event_type so fetch them from the main doc
            if (StringUtils.isNotBlank(dataSegment)) {
                List<String> responseValues = field.values;
                Object dataSegmentObject = getValue(event, dataSegment);
                if (dataSegmentObject != null) {
                    if (dataSegmentObject instanceof List) {

                        List dataSegmentList = (List) dataSegmentObject;
                        // Iterate in the segment e.g obs segment
                        for (Object segment : dataSegmentList) {
                            // let's discuss this further, to get the real value in the doc we've to
                            // use the keys 'fieldcode' and 'value'
                            Object value = getValue(segment, fieldName);
                            String docSegmentFieldValue = value != null ? value.toString() : "";
                            Object values = getValue(segment, responseKey);
                            List<String> docSegmentResponseValues = new ArrayList<>();
                            if (values instanceof List) {
                                docSegmentResponseValues = getValues((List) values);
                            }

                            if (docSegmentFieldValue.equalsIgnoreCase(fieldValue) && (!Collections
                                    .disjoint(responseValues, docSegmentResponseValues))) {
                                // this is the event obs we're interested in put it in the respective
                                // bucket specified by type variable
                                processCaseModel(event, client, createsCase);
                                closeCase(client, closesCase);
                            }

                        }
                    } else if (dataSegmentObject instanceof Map) {
                        Map map = (Map) dataSegmentObject;
                        // This means field_value and response_key are null so pick the
                        // value from the json object for the field_name
                        if (map.containsKey(fieldName)) {
                            Object objectValue = map.get(fieldName);
                            if (objectValue != null && objectValue instanceof String) {
                                String docSegmentFieldValue = objectValue.toString();
                                if (docSegmentFieldValue.equalsIgnoreCase(fieldValue)) {
                                    processCaseModel(event, client, createsCase);
                                    closeCase(client, closesCase);
                                }
                            }
                        }
                    }
                }

            } else {
                //fetch from the main doc
                Object value = getValue(event, fieldName);
                String docSegmentFieldValue = value != null ? value.toString() : "";
                if (docSegmentFieldValue.equalsIgnoreCase(fieldValue)) {
                    processCaseModel(event, client, createsCase);
                    closeCase(client, closesCase);
                }
            }
            return true;
        } catch (Exception e) {
            Timber.e(e);
            return null;
        }
    }

    public  ClientProcessorForJava(Context context);

}