// Path: CPOrm/src/main/java/za/co/cporm/model/generate/TableDetails.java
// public static class ColumnDetails{
//     private final String columnName;
//     private final Field columnField;
//     private final SqlColumnMapping columnTypeMapping;
//     private final boolean primaryKey;
//     private final boolean unique;
//     private final boolean required;
//     private final boolean autoIncrement;
//     private final boolean notifyChanges;
// 
//     public ColumnDetails(String columnName, Field columnField, SqlColumnMapping columnTypeMapping, boolean primaryKey, boolean unique, boolean required, boolean autoIncrement, boolean notifyChanges) {
//         this.columnName = columnName;
//         this.columnField = columnField;
//         this.columnTypeMapping = columnTypeMapping;
//         this.primaryKey = primaryKey || autoIncrement;
//         this.unique = unique;
//         this.required = required;
//         this.autoIncrement = autoIncrement;
//         this.notifyChanges = notifyChanges;
// 
//         if(primaryKey && !required) throw new IllegalStateException("Column must be not required if primary key is set");
// 
//         if(TextUtils.isEmpty(columnName)) throw new IllegalArgumentException("A valid column name needs to be provided");
// 
//         columnField.setAccessible(true);
//     }
// 
//     public String getColumnName() {
//         return columnName;
//     }
// 
//     public SqlColumnMapping getColumnTypeMapping() {
//         return columnTypeMapping;
//     }
// 
//     public Field getColumnField() {
//         return columnField;
//     }
// 
//     public boolean isPrimaryKey() {
//         return primaryKey;
//     }
// 
//     public boolean isUnique() {
//         return unique;
//     }
// 
//     public boolean isRequired() {
//         return required;
//     }
// 
//     public boolean isAutoIncrement() {
//         return autoIncrement;
//     }
// 
//     public boolean notifyChanges() {
// 
//         return notifyChanges;
//     }
// 
//     public void setFieldValue(Cursor cursor, int columnIndex, Object dataModelObject) throws IllegalAccessException {
// 
//         columnField.set(dataModelObject, columnTypeMapping.getColumnValue(cursor, columnIndex));
//     }
// 
//     public void setContentValue(ContentValues contentValues, Object dataModelObject) throws IllegalAccessException {
// 
//         Object value = columnField.get(dataModelObject);
// 
//         if (value == null) contentValues.putNull(columnName);
//         else columnTypeMapping.setColumnValue(contentValues, columnName, value);
//     }
// 
//     public <T> void setFieldValue(Bundle bundle, String columnName, T dataModelObject) throws IllegalAccessException {
// 
//         columnField.set(dataModelObject, columnTypeMapping.getColumnValue(bundle, columnName));
//     }
// }


import za.co.cporm.model.annotation.Index;
import za.co.cporm.model.annotation.TableConstraint;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import static za.co.cporm.model.generate.TableDetails.ColumnDetails;
package za.co.cporm.model.generate;




/**
 * The java object will be converted to a table details object and the supplied information is then used to generate the
 * statements.
 */
public class TableGenerator {

    public static String generateTableDrop(TableDetails tableDetails, boolean prettyPrint){
        StringBuilder tableQuery = new StringBuilder();

        prettyPrint(0, prettyPrint,  tableQuery);
        tableQuery.append("DROP TABLE IF EXISTS ");
        tableQuery.append(tableDetails.getTableName());
        tableQuery.append(";");

        return tableQuery.toString();
    }

    public static String generateTableCreate(TableDetails tableDetails, boolean prettyPrint) {
        StringBuilder tableQuery = new StringBuilder();

        prettyPrint(0, prettyPrint,  tableQuery);
        tableQuery.append("CREATE TABLE ");
        tableQuery.append(tableDetails.getTableName());

        prettyPrint(1, prettyPrint,  tableQuery);
        tableQuery.append("(");
        prettyPrint(1, prettyPrint,  tableQuery);

        Iterator<ColumnDetails> columnIterator = tableDetails.getColumns().iterator();
        while(columnIterator.hasNext()) {
// Path: CPOrm/src/main/java/za/co/cporm/model/generate/TableDetails.java
// public static class ColumnDetails{
//     private final String columnName;
//     private final Field columnField;
//     private final SqlColumnMapping columnTypeMapping;
//     private final boolean primaryKey;
//     private final boolean unique;
//     private final boolean required;
//     private final boolean autoIncrement;
//     private final boolean notifyChanges;
// 
//     public ColumnDetails(String columnName, Field columnField, SqlColumnMapping columnTypeMapping, boolean primaryKey, boolean unique, boolean required, boolean autoIncrement, boolean notifyChanges) {
//         this.columnName = columnName;
//         this.columnField = columnField;
//         this.columnTypeMapping = columnTypeMapping;
//         this.primaryKey = primaryKey || autoIncrement;
//         this.unique = unique;
//         this.required = required;
//         this.autoIncrement = autoIncrement;
//         this.notifyChanges = notifyChanges;
// 
//         if(primaryKey && !required) throw new IllegalStateException("Column must be not required if primary key is set");
// 
//         if(TextUtils.isEmpty(columnName)) throw new IllegalArgumentException("A valid column name needs to be provided");
// 
//         columnField.setAccessible(true);
//     }
// 
//     public String getColumnName() {
//         return columnName;
//     }
// 
//     public SqlColumnMapping getColumnTypeMapping() {
//         return columnTypeMapping;
//     }
// 
//     public Field getColumnField() {
//         return columnField;
//     }
// 
//     public boolean isPrimaryKey() {
//         return primaryKey;
//     }
// 
//     public boolean isUnique() {
//         return unique;
//     }
// 
//     public boolean isRequired() {
//         return required;
//     }
// 
//     public boolean isAutoIncrement() {
//         return autoIncrement;
//     }
// 
//     public boolean notifyChanges() {
// 
//         return notifyChanges;
//     }
// 
//     public void setFieldValue(Cursor cursor, int columnIndex, Object dataModelObject) throws IllegalAccessException {
// 
//         columnField.set(dataModelObject, columnTypeMapping.getColumnValue(cursor, columnIndex));
//     }
// 
//     public void setContentValue(ContentValues contentValues, Object dataModelObject) throws IllegalAccessException {
// 
//         Object value = columnField.get(dataModelObject);
// 
//         if (value == null) contentValues.putNull(columnName);
//         else columnTypeMapping.setColumnValue(contentValues, columnName, value);
//     }
// 
//     public <T> void setFieldValue(Bundle bundle, String columnName, T dataModelObject) throws IllegalAccessException {
// 
//         columnField.set(dataModelObject, columnTypeMapping.getColumnValue(bundle, columnName));
//     }
// }


// Path: CPOrm/src/main/java/za/co/cporm/model/generate/TableGenerator.java
import za.co.cporm.model.annotation.Index;
import za.co.cporm.model.annotation.TableConstraint;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import static za.co.cporm.model.generate.TableDetails.ColumnDetails;

package za.co.cporm.model.generate;




/**
 * The java object will be converted to a table details object and the supplied information is then used to generate the
 * statements.
 */
public class TableGenerator {

    public static String generateTableDrop(TableDetails tableDetails, boolean prettyPrint){
        StringBuilder tableQuery = new StringBuilder();

        prettyPrint(0, prettyPrint,  tableQuery);
        tableQuery.append("DROP TABLE IF EXISTS ");
        tableQuery.append(tableDetails.getTableName());
        tableQuery.append(";");

        return tableQuery.toString();
    }

    public static String generateTableCreate(TableDetails tableDetails, boolean prettyPrint) {
        StringBuilder tableQuery = new StringBuilder();

        prettyPrint(0, prettyPrint,  tableQuery);
        tableQuery.append("CREATE TABLE ");
        tableQuery.append(tableDetails.getTableName());

        prettyPrint(1, prettyPrint,  tableQuery);
        tableQuery.append("(");
        prettyPrint(1, prettyPrint,  tableQuery);

        Iterator<ColumnDetails> columnIterator = tableDetails.getColumns().iterator();
        while(columnIterator.hasNext()) {
            ColumnDetails columnDetails = columnIterator.next();