package ${enum.getPackageName()};

import java.util.List;

import org.apache.commons.lang.enum.Enum;
import org.asyrinx.brownie.core.lang.enum.ValuedEnum;

#macro( writeNewValueObj $valueType $valueVariableName )
#if ( ${valueType.isPrimitive()} )new ${valueType.toClass().Name}(${valueVariableName}) #else ${valueVariableName} #end
#end
/** 
 * 
#if ($addTimeStamp)
 * generated by joey-gen on $now
#end
 */
public class ${enum.getName()} extends ValuedEnum {
	private ${enum.getName()}(String caption, ${enum.getValueTypeObj().getName()} value) {
		super(caption, #writeNewValueObj(${enum.ValueTypeObj} "value") );
	}
	public ${enum.ValueTypeObj.Name} as${stringUtils.capitalize( ${enum.ValueTypeObj.Name} )}() {
#if ( ${enum.ValueTypeObj.isPrimitive()} )
		return ((${enum.ValueTypeObj.toClass().Name}) getValue()).${enum.ValueTypeObj.Name}Value();
#else
		return (${enum.ValueTypeObj.toClass().Name}) getValue();
#end
	}
	public static ${enum.Name} get(${enum.ValueTypeObj.Name} value) {
		return (${enum.Name}) ValuedEnum.getEnum(${enum.Name}.class,
			#writeNewValueObj(${enum.ValueTypeObj} "value") );
	}

	public static List getList() {
		return Enum.getEnumList(${enum.Name}.class);
	}
	public static ${enum.Name} getEnum(String name) {
		return (${enum.Name}) Enum.getEnum(${enum.Name}.class, name);
	}
	public String toString() {
		return getName();
	}

#macro( writeDefaultValue $valueType $valueVariableName )
#if ( ${valueType.getName()} == "String" ) 
#set ( $valueVariableName = "'$valueVariableName'" )
#end
#if ( ${valueType.isPrimitive()} )${valueVariableName}#elseif(${valueType.Category.Name} == "number")new ${valueType.toClass().Name}(${valueVariableName})#else${valueVariableName}#end
#end
	
#foreach ( $entry in ${enum.iterator()} )
	public static final ${enum.Name} ${entry.Name.toUpperCase()} = new ${enum.Name}("${entry.Label}", #writeDefaultValue(${enum.ValueTypeObj} ${entry.getValue()}) );
#end
}