class SQLiteUtils {

    @NonNull
    @SuppressWarnings("unchecked")
    static String createColumnDefinition(TableInfo tableInfo, Field field) {
        StringBuilder definition = new StringBuilder();

        Column column = field.getAnnotation(Column.class);
        Unique uniqueAnnotation = field.getAnnotation(Unique.class);
        Class type = field.getType();
        ColumnInfo columnInfo = tableInfo.getColumnInfo(field);
        SQLiteType sqliteType = columnInfo.type;

        definition.append("`");
        definition.append(columnInfo.name);
        definition.append("`");
        definition.append(" ");
        definition.append(sqliteType.getName());

        if (!TextUtils.isEmpty(definition)) {
            if (columnInfo.name.equals(tableInfo.getPrimaryKeyColumnName())) {
                definition.append(" PRIMARY KEY AUTOINCREMENT");
            } else if (column != null) {
                if (column.length() > -1) {
                    definition.append("(");
                    definition.append(column.length());
                    definition.append(")");
                }

                if (column.collate() != Collate.NONE) {
                    definition.append(" COLLATE ");
                    definition.append(column.collate().toString());
                }

                if (column.notNull()) {
                    definition.append(" NOT NULL ON CONFLICT ");
                    definition.append(column.onNullConflict().toString());
                }

                if (uniqueAnnotation != null && uniqueAnnotation.unique()) {
                    definition.append(" UNIQUE ON CONFLICT ");
                    definition.append(uniqueAnnotation.onUniqueConflict().toString());
                }

            }

            if (ReflectionUtils.isModel(type)) {
                TableInfo foreignKeyTableInfo = ReActiveAndroid.getTableInfo(type);
                definition.append(" REFERENCES ");
                definition.append(foreignKeyTableInfo.getTableName());
                definition.append("(`").append(foreignKeyTableInfo.getPrimaryKeyColumnName()).append("`)");
                definition.append(" ON DELETE ");
                definition.append(column.onDelete().toString().replace("_", " "));
                definition.append(" ON UPDATE ");
                definition.append(column.onUpdate().toString().replace("_", " "));
            }
        } else {
            ReActiveLog.e(LogLevel.BASIC, "No type mapping for: " + type.toString());
        }

        return definition.toString();
    }

}