/**
  * Generates an Enum class for method params that have an allowed values list.
  *
  * @param resources
  * @param templateGroup
  */
 private void generateEnumForAllowedValues(
     List<Resource> resources, StringTemplateGroup templateGroup) {
   List<String> generatedEnums = new ArrayList<String>();
   StringTemplate template;
   String valuePrefix, valueSuffix = "";
   String enumName;
   for (Resource resource : resources) {
     if (resource.getEndPoints() != null) {
       for (Endpoint endpoint : resource.getEndPoints()) {
         if (endpoint.getOperations() != null) {
           for (EndpointOperation operation : endpoint.getOperations()) {
             // ResourceMethod method = operation.generateMethod(endpoint, resource, config);
             if (operation.getParameters() != null) {
               for (ModelField operationParam : operation.getParameters()) {
                 // skipping the case where there is just one item - TODO process case of
                 // allowableValue like '0 to 1000'
                 if (operationParam.getAllowableValues() != null
                     && operationParam
                         .getAllowableValues()
                         .getClass()
                         .isAssignableFrom(AllowableListValues.class)) {
                   if (!generatedEnums.contains(operationParam.getName())) {
                     // generate enum
                     template = templateGroup.getInstanceOf(ENUM_OBJECT_TEMPLATE);
                     List<String> imports = new ArrayList<String>();
                     imports.addAll(this.config.getDefaultModelImports());
                     enumName = this.getNameGenerator().getEnumName(operationParam.getName());
                     template.setAttribute("className", enumName);
                     template.setAttribute("description", operationParam.getDescription());
                     template.setAttribute(
                         "enumValueType",
                         this.getDataTypeMappingProvider()
                             .getClassType(operationParam.getDataType(), true));
                     for (String allowableValue :
                         ((AllowableListValues) operationParam.getAllowableValues()).getValues()) {
                       if (operationParam.getDataType().equalsIgnoreCase("string")) {
                         valuePrefix = valueSuffix = "\"";
                       } else {
                         valuePrefix = valueSuffix = "";
                       }
                       ;
                       String namePrefix = "";
                       if (isNameStartsWithInteger(allowableValue)
                           && !canEnumNameStartsWithNumber()) {
                         namePrefix = "ENUM_";
                       }
                       template.setAttribute(
                           "values.{name,value}",
                           namePrefix
                               + this.getNameGenerator()
                                   .applyClassNamingPolicy(allowableValue.replaceAll("-", "_")),
                           this.getNameGenerator()
                               .applyMethodNamingPolicy(
                                   valuePrefix.concat(allowableValue).concat(valueSuffix)));
                     }
                     template.setAttribute(PACKAGE_NAME, config.getModelPackageName());
                     File aFile =
                         new File(
                             languageConfig.getModelClassLocation()
                                 + enumName
                                 + languageConfig.getClassFileExtension());
                     writeFile(aFile, template.toString(), "Enum class");
                     generatedEnums.add(operationParam.getName());
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
 }