class B2DeleteFeature implements Delete {

    @Override
    public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException {
        for(Path file : files.keySet()) {
            if(containerService.isContainer(file)) {
                continue;
            }
            callback.delete(file);
            if(file.getType().contains(Path.Type.upload)) {
                new B2LargeUploadPartService(session, fileid).delete(file.attributes().getVersionId());
            }
            else {
                if(file.isDirectory()) {
                    // Delete /.bzEmpty if any
                    final String fileid;
                    try {
                        fileid = this.fileid.getFileid(file, new DisabledListProgressListener());
                    }
                    catch(NotfoundException e) {
                        log.warn(String.format("Ignore failure %s deleting placeholder file for %s", e, file));
                        continue;
                    }
                    try {
                        session.getClient().deleteFileVersion(containerService.getKey(file), fileid);
                    }
                    catch(B2ApiException e) {
                        log.warn(String.format("Ignore failure %s deleting placeholder file for %s", e.getMessage(), file));
                    }
                    catch(IOException e) {
                        throw new DefaultIOExceptionMappingService().map(e);
                    }
                }
                else if(file.isFile()) {
                    try {
                        session.getClient().deleteFileVersion(containerService.getKey(file), fileid.getFileid(file, new DisabledListProgressListener()));
                    }
                    catch(B2ApiException e) {
                        throw new B2ExceptionMappingService().map("Cannot delete {0}", e, file);
                    }
                    catch(IOException e) {
                        throw new DefaultIOExceptionMappingService().map(e);
                    }
                }
            }
        }
        for(Path file : files.keySet()) {
            try {
                if(containerService.isContainer(file)) {
                    callback.delete(file);
                    // Finally delete bucket itself
                    session.getClient().deleteBucket(fileid.getFileid(file, new DisabledListProgressListener()));
                }
            }
            catch(B2ApiException e) {
                throw new B2ExceptionMappingService().map("Cannot delete {0}", e, file);
            }
            catch(IOException e) {
                throw new DefaultIOExceptionMappingService().map(e);
            }
        }
    }

    public  B2DeleteFeature(final B2Session session, final B2FileidProvider fileid);

}