package apoc.monitor;

import apoc.result.StoreInfoResult;
import org.apache.commons.io.FileUtils;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.kernel.database.Database;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.procedure.Context;
import org.neo4j.procedure.Description;
import org.neo4j.procedure.Procedure;

import java.io.File;
import java.util.stream.Stream;

public class Store  {

    @Context
    public GraphDatabaseService db;

    @Procedure
    @Description("apoc.monitor.store() returns informations about the sizes of the different parts of the neo4j graph store")
    public Stream<StoreInfoResult> store() {

        Database database = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(Database.class);
        DatabaseLayout databaseLayout = database.getDatabaseLayout();
        return Stream.of(new StoreInfoResult(
                getDirectorySize(databaseLayout.getTransactionLogsDirectory()),
                databaseLayout.propertyStringStore().length(),
                databaseLayout.propertyArrayStore().length(),
                databaseLayout.relationshipStore().length(),
                databaseLayout.propertyStore().length(),
                getDirectorySize(databaseLayout.databaseDirectory()), //databaseLayout.storeFiles().stream().mapToLong(File::length).sum(),
                databaseLayout.nodeStore().length()
        ));
    }

    private long getDirectorySize(File folder) {
        return folder.exists() ? FileUtils.sizeOfDirectory(folder) : 0;
    }


}

@@ -1009,16 +1009,25 @@
 ectory()
+.toFile()
 ),%0A     
@@ -1066,32 +1066,41 @@
 tyStringStore().
+toFile().
 length(),%0A      
@@ -1137,32 +1137,41 @@
 rtyArrayStore().
+toFile().
 length(),%0A      
@@ -1207,32 +1207,41 @@
 tionshipStore().
+toFile().
 length(),%0A      
@@ -1273,32 +1273,41 @@
 propertyStore().
+toFile().
 length(),%0A      
@@ -1367,16 +1367,25 @@
 ectory()
+.toFile()
 ), //dat
@@ -1488,24 +1488,33 @@
 nodeStore().
+toFile().
 length()%0A   

fix compilation issues