class SchemaToJsonMapper {

    public static String getCreateTableStatementFromJson( @NonNull String json, boolean createPrimaryKey, boolean addDefaultValueDefinition, @NonNull String schemaName, String tableName, String storeName ) {
        JsonTable table = gson.fromJson( json, JsonTable.class );
        SqlWriter writer = new SqlPrettyWriter( PolyphenyDbSqlDialect.DEFAULT, true, null );
        writer.keyword( "CREATE TABLE" );

        // Print schemaName.tableName
        SqlWriter.Frame identifierFrame = writer.startList( SqlWriter.FrameTypeEnum.IDENTIFIER );
        writer.identifier( schemaName );
        writer.sep( ".", true );
        if ( tableName != null ) {
            writer.identifier( tableName );
        } else {
            writer.identifier( table.tableName );
        }
        writer.endList( identifierFrame );

        // Print column list
        SqlWriter.Frame columnFrame = writer.startList( "(", ")" );
        for ( JsonColumn column : table.columns ) {
            writer.sep( "," );
            writer.identifier( column.columnName );
            writer.keyword( column.type );
            if ( column.length != null ) {
                SqlWriter.Frame columnTypeFrame = writer.startList( SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")" );
                writer.print( column.length );
                if ( column.scale != null ) {
                    writer.sep( ",", true );
                    writer.print( column.scale );
                }
                writer.endList( columnTypeFrame );
            }
            if ( !column.nullable ) {
                writer.keyword( "NOT NULL" );
            }
            if ( addDefaultValueDefinition ) {
                if ( column.defaultValue != null ) {
                    writer.keyword( "DEFAULT" );
                    if ( Arrays.asList( PolyType.VARCHAR.name(), PolyType.DATE.name(), PolyType.TIME.name(), PolyType.TIMESTAMP.name() ).contains( column.type ) ) {
                        writer.literal( "'" + column.defaultValue + "'" );
                    } else {
                        writer.literal( column.defaultValue );
                    }
                } else if ( column.defaultFunctionName != null ) {
                    writer.keyword( "DEFAULT" );
                    writer.print( column.defaultFunctionName );
                }
            }
        }
        if ( createPrimaryKey && table.primaryKeyColumnNames != null ) {
            writer.sep( "," );
            writer.keyword( "PRIMARY KEY" );
            SqlWriter.Frame primaryKeyFrame = writer.startList( SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")" );
            for ( String columnName : table.primaryKeyColumnNames ) {
                writer.sep( "," );
                writer.identifier( columnName );
            }
            writer.endList( primaryKeyFrame );
        }
        writer.endList( columnFrame );

        // ON STORE storeName
        if ( storeName != null ) {
            writer.keyword( "ON STORE" );
            writer.identifier( storeName );
        }

        return writer.toSqlString().getSql();
    }

}