package com.yahoo.squidb.processor.plugins.defaults.properties.generators;

import com.yahoo.aptutils.model.CoreTypes;
import com.yahoo.aptutils.model.DeclaredTypeName;
import com.yahoo.aptutils.utils.AptUtils;
import com.yahoo.aptutils.writer.JavaFileWriter;
import com.yahoo.aptutils.writer.expressions.Expressions;
import com.yahoo.squidb.processor.data.ModelSpec;

import java.io.IOException;

import javax.lang.model.element.VariableElement;

/**
 * Special case of BasicLongPropertyGenerator specific to ROWID or INTEGER PRIMARY KEY properties that generates
 * the extra methods required for TableModels
 */
public class RowidPropertyGenerator extends BasicLongPropertyGenerator {

    public RowidPropertyGenerator(ModelSpec<?> modelSpec, String columnName, AptUtils utils) {
        super(modelSpec, columnName, utils);
    }

    public RowidPropertyGenerator(ModelSpec<?> modelSpec, String columnName,
            String propertyName, AptUtils utils) {
        super(modelSpec, columnName, propertyName, utils);
    }

    public RowidPropertyGenerator(ModelSpec<?> modelSpec, VariableElement field, AptUtils utils) {
        super(modelSpec, field, utils);
    }

    @Override
    public DeclaredTypeName getTypeForAccessors() {
        return CoreTypes.PRIMITIVE_LONG;
    }

    @Override
    protected void writeGetterBody(JavaFileWriter writer) throws IOException {
        writer.writeStatement(Expressions.returnExpr(Expressions.fromString("super.getRowId()")));
    }

    @Override
    protected void writeSetterBody(JavaFileWriter writer, String argName) throws IOException {
        writer.writeStringStatement("super.setRowId(" + argName + ")");
        writer.writeStringStatement("return this");
    }
}

@@ -1275,32 +1275,562 @@
 VE_LONG;%0A    %7D%0A%0A
+    @Override%0A    public String getterMethodName() %7B%0A        // Camel case translation doesn't quite work in this case, so override%0A        if (%22ROWID%22.equals(propertyName)) %7B%0A            return %22getRowId%22;%0A        %7D%0A        return super.getterMethodName();%0A    %7D%0A%0A    @Override%0A    public String setterMethodName() %7B%0A        // Camel case translation doesn't quite work in this case, so override%0A        if (%22ROWID%22.equals(propertyName)) %7B%0A            return %22setRowId%22;%0A        %7D%0A        return super.setterMethodName();%0A    %7D%0A%0A
     @Override%0A  

Fix camelcase issue with rowid name in RowidPropertyGenerator