class PersonQueryBuilder extends AbstractQueryBuilder<PersonList> {

	@Override
	protected BaseQueryBuilder build(final PersonList context, final BaseQueryBuilder builder) {
		Function<Object, String> docNumFunction = value -> {
			return "LOWER(e.docNum) LIKE LOWER('%" + value + "%') ";
		};

		return builder
				.where()
				.openBracket()
					.addAndCondition(PERSON_TYPES_CONDITION, context.getPersonTypes())
					.addAndCondition(GENDERTYPES_CONDITION, context.getGenderTypes())
					.addAndCondition(MARRIEDTYPES_CONDITION, context.getMarriedTypes())
					.addAndCondition(PARENTS_CONDITION, context.getParents())
					.addAndCondition(CITIZEN_COUNTRIES_CONDITION, context.getCitizenCountries())

					.addAndConditionForLoop(value -> MessageFormat.format(NAMES_CONDITIOIN_PLACEHOLDER, value), context.getNames())
					.addAndConditionForLoop(value -> MessageFormat.format(FIRSTNAMES_CONDITIOIN_PLACEHOLDER, value), context.getFirstNames())
					.addAndConditionForLoop(value -> MessageFormat.format(SURNNAMES_CONDITIOIN_PLACEHOLDER, value), context.getSurnames())
					.addAndConditionForLoop(value -> MessageFormat.format(FATHERNAMES_CONDITIOIN_PLACEHOLDER, value), context.getFatherNames())
					.addAndConditionForLoop(value -> MessageFormat.format(PHOTOS_CONDITIOIN_PLACEHOLDER, value), context.getPhotos())
					.addAndConditionForLoop(value -> MessageFormat.format(DOCSERIES_CONDITIOIN_PLACEHOLDER, value), context.getDocSeries())
					.addAndConditionForLoop(docNumFunction, context.getDocNums())
					.addAndConditionForLoop(value -> MessageFormat.format(IDENTIFIERS_CONDITIOIN_PLACEHOLDER, value), context.getIdentifiers())
					.addAndConditionForLoop(value -> MessageFormat.format(BIRTHPLACES_CONDITIOIN_PLACEHOLDER, value), context.getBirthPlaces())

					.addAndCondition(RESIDENT_CONDITION, context.getResident())
					.addAndCondition(BEGDATE_CONDITION, context.getBegDate())
					.addAndCondition(ENDDATE_CONDITION, context.getEndDate())
					.addAndCondition(ISMILITARY_CONDITION, context.getIsMilitary())
					.addAndCondition(ISHOSTEL_CONDITION, context.getIsHostel())
				.closeBracket();
	}

}