package org.nexusdata.modelgen.metamodel;

import java.util.HashMap;
import java.util.Map;

public class Attribute  extends Property {

    private static final Map<String,String> typeToJavaType = new HashMap<>();
    static
    {
        typeToJavaType.put("String", "String");
        typeToJavaType.put("Int", "Integer");
        typeToJavaType.put("Long", "Long");
        typeToJavaType.put("Bool", "Boolean");
        typeToJavaType.put("Date", "Date");
    }

    private Entity entity;
    private String type;

    // use to set parent entity when object is de-serialized
    public void setEntity(Entity entity) {
        this.entity = entity;
    }

    @Override
    public String getJavaType() {
        String javaType = typeToJavaType.get(type);
        if (javaType == null) {
            if (isEnumProperty(type)) {
                javaType = type;
            }
        }
        if (javaType == null) {
            throw new RuntimeException("Unknown type '" + type + "' for attribute '" + name + "'");
        }
        return javaType;
    }

    private boolean isEnumProperty(String name) {
        for (EnumProperty enumProp : entity.getEnums()) {
            if (enumProp.getName().equals(name)) {
                return true;
            }
        }

        return false;
    }
}

@@ -1297,11 +1297,355 @@
 e;%0A    %7D
+%0A%0A    public String getMethodNameForGetter() %7B%0A        if (type.equals(%22Bool%22)) %7B%0A            if (name.substring(0, 2).equalsIgnoreCase(%22is%22)) %7B%0A                return name;%0A            %7D else %7B%0A                return %22is%22 + getCapitalizedName();%0A            %7D%0A        %7D else %7B%0A            return super.getMethodNameForGetter();%0A        %7D%0A    %7D
 %0A%7D%0A

use is<AttributeName> as method name for boolean properties