class DefaultDirectoryMigrator implements Migrator {

    @Override
    public List<Path> migrate(List<Path> srcDirectoriesPaths, Path destDirectoryPath) throws IOException {
        Objects.requireNonNull(srcDirectoriesPaths, "Src directories should not be null");
        Objects.requireNonNull(destDirectoryPath, "Dest directory should not be null");

        List<Path> listOfMigratedSrcPaths = new ArrayList<>();
        if (!Files.exists(destDirectoryPath) || Files.isDirectory(destDirectoryPath) && Files.exists(destDirectoryPath)) {
            Path tempDirectory = Files.createTempDirectory("migration-temp-dir");
            try {
                boolean migrated = false;
                for (Path p : srcDirectoriesPaths) {
                    if (Files.exists(p)) {
                        if (Files.isDirectory(p)) {
                            if (com.apollocurrency.aplwallet.apl.util.FileUtils.countElementsOfDirectory(p) > 0) {
                                if (!p.equals(destDirectoryPath)) {
                                    listOfMigratedSrcPaths.add(p);
                                    FileUtils.copyDirectory(p.toFile(), tempDirectory.toFile());
                                    migrated = true;
                                }
                            }
                        } else
                            throw new IllegalArgumentException("List of src directories should contain only directories");
                    }
                }
                if (migrated) {
                    FileUtils.copyDirectory(tempDirectory.toFile(), destDirectoryPath.toFile());
                }
            } finally {
                FileUtils.deleteDirectory(tempDirectory.toFile());

            }
        } else throw new IllegalArgumentException("Destionation path is not a directory");
        return listOfMigratedSrcPaths;
    }

}