<%@ import val generator: org.fusesource.ide.generator.Generator %>
<%
  import org.fusesource.camel.tooling.util.Languages

  val langTool = new Languages()
%>
{
  "definitions": {
     "endpoint": {
				"type": "object",
				"extends": {
					"type": "org.apache.camel.model.OptionalIdentifiedDefinition"
				},
				"properties": {
					"uri": {
						"type": "string"
					},
					"ref": {
						"type": "string"
					}
				}
      },
     "from": {
        "title":    "From",
				"type": "object",
				"extends": {
					"type": "endpoint"
				},
        "group":   "Endpoints",
        "description":  "Consumes from an endpoint",
        "tooltip":  "Consumes from an endpoint",
        "icon":     "endpoint24.png"
      },
     "to": {
        "title":    "To",
				"type": "object",
				"extends": {
					"type": "endpoint"
				},
        "group":   "Endpoints",
        "description":  "Sends messages to an endpoint",
        "tooltip":  "Sends messages to an endpoint",
        "icon":     "endpoint24.png"
      },
     "route": {
        "title":    "Route",
        "group":   "",
        "description":  "A collection of EIP steps",
        "tooltip":  "A collection of EIP steps",
        "icon":     "route24.png"
      },
			"org.apache.camel.model.OptionalIdentifiedDefinition": {
				"type": "object",
				"properties": {
					"id": {
						"type": "string"
					},
					"description": {
						"type": "org.apache.camel.model.DescriptionDefinition"
					},
					"inheritErrorHandler": {
						"type": "java.lang.Boolean"
					}
				}
			},
			"org.apache.camel.model.language.ExpressionDefinition": {
	      "description": "A Camel expression",
	      "tooltip": "Pick an expression language and enter an expression",
				"type": "object",
	      "properties": {
	        "expression": {
	          "type": "java.lang.String",
	          "description": "The expression",
	          "tooltip": "Enter the expression in your chosen Came expression language",
	          "title": "expression"
	        },
	        "language": {
	          "type": "java.lang.String",
	          "description": "The camel expression language ot use",
	          "tooltip": "Pick the expression language you want to use",
	          "title": "language"
	        }
	      }
			},

#for( node <- nodeDefinitions)
<%
    println("Searching for " + node.id + "24" + " in " + sourceDir);
    val icon = findIconFileOrElse("", node.id + "24", node.defaultImageName + "24.png")
 %>
     "${node.id}": {
			"type": "object",
			"extends": {
				"type": "org.apache.camel.model.OptionalIdentifiedDefinition"
			},
      "title":    "${node.title}",
      "group":   "${node.group}",
      "description":  "${node.description}",
      "tooltip":  "${node.description}",
      "icon":     "${icon}",
			#if (node.canAcceptInput())
      "acceptInput": true,
      #end
      "properties": {
	<%
	comma(node.beanProperties){ prop =>
		val xmlElements = node.xmlElements(prop) 
	%>		
        "${prop.name}": {
    #if (!xmlElements.isEmpty)
						"type": [
							<%
							comma(xmlElements){ xe =>
							%>		
				       "${xe.`type`().getName}"
 						 	<%
 						 	}
 						 	%>				
							],
		#else
      #if (node.isBeanMethod(prop))
					"control":   "combo",
					"kind": "beanMethod",
          "title":"Select a method...",
      #elif (node.isBeanRef(prop))
        "control":   "combo",
				"kind":   "beanRef",
				"title": "Select a bean...",
	    #elif (isExpression(prop))
				"kind" : "expression",
      #else
      #end
	        "type":   "${javaScriptType(prop)}",
					#end
          "description":"${prop.description}",
          "tooltip":"${prop.description}",
					#if (prop.readOnly)
          "readonly": true,
		      #end
					#if (prop.optional && !node.isRequired(prop))
          "optional": true,
		      #end
					#if (wrapLines(prop))
          "wrapLines": true,
		      #end
          "title":  "${prop.label}"
        }
	<%
	}
	%>				
			}
    },
#end
<%
comma(baseClassAndNestedClasses){ node =>
%>		
     "${node.id}": {
 			"type": "object",
      "description":  "${node.description}",
      "tooltip":  "${node.description}",
      "properties": {
	<%
	comma(node.beanProperties){ prop =>
	%>		
        "${prop.name}": {
				  <% 
					val xmlElements = node.xmlElements(prop) 
					%>
				    #if (xmlElements.isEmpty)
				  	#else
						"elements": {
							<%
							comma(xmlElements){ xe =>
							%>		
				       "${xe.name()}": "${xe.`type`().getName}"
						 	<%
						 	}
						 	%>				
							},
				  	#end
      #if (node.isBeanMethod(prop))
					"control":   "combo",
					"kind": "beanMethod",
          "title":'Select a method...',
      #elif (node.isBeanRef(prop))
        "control":   "combo",
				"kind":   "beanRef",
				"title": "Select a bean...",
	    #elif (isExpression(prop))
				"kind" : "expression",
      #else
      #end
	        "type":   "${javaScriptType(prop)}",
          <%--
					"type": "${propertyType(prop)}"
					--%>
          "description":"${prop.description}",
          "tooltip":"${prop.description}",
					#if (prop.readOnly)
          "readonly": true,
		      #end
					#if (prop.optional && !node.isRequired(prop))
          "optional": true,
		      #end
					#if (wrapLines(prop))
          "wrapLines": true,
		      #end
          "title":  "${prop.label}"
        }
	<%
	}
	%>				
			}
    }
<%
}
%>				
	},
	"languages": {
<%
comma(langTool.languages){ lang =>
%>		
    "${lang.id}": {
      "name": "${lang.name}",
      "description": "${lang.description}"
    }
<%
}
%>				
	}
}