// Path: client/src/main/java/com/github/e13mort/stf/console/commands/cache/DeviceListCache.java
// public interface DeviceListCache {
//     static DeviceListCache getCache() {
//         return new DeviceListCacheImpl();
//     }
// 
//     DeviceListCache EMPTY = new DeviceListCache() {
//         @Override
//         public CacheTransaction beginTransaction() {
//             return CacheTransaction.EMPTY;
//         }
// 
//         @Override
//         public List<Device> getCachedFiles() {
//             return Collections.emptyList();
//         }
//     };
// 
//     CacheTransaction beginTransaction();
// 
//     List<Device> getCachedFiles();
// 
//     interface CacheTransaction {
//         CacheTransaction EMPTY = new CacheTransaction() {
//             @Override
//             public void addDevice(Device device) {
// 
//             }
// 
//             @Override
//             public void save() {
// 
//             }
//         };
// 
//         void addDevice(Device device);
// 
//         void save();
//     }
// }


import com.github.e13mort.stf.client.FarmClient;
import com.github.e13mort.stf.client.parameters.DevicesParams;
import com.github.e13mort.stf.console.commands.cache.DeviceListCache;
import io.reactivex.Flowable;
import java.util.Collection;
package com.github.e13mort.stf.console.commands.devices;



class DocumentsLoader {

    private final FarmClient client;
    private final DevicesParams params;
    private DeviceMapper fieldsReader = DeviceMapper.EMPTY;
    private DeviceListCache deviceListCache = DeviceListCache.EMPTY;

    public DocumentsLoader(FarmClient client, DevicesParams params) {
        this.client = client;
        this.params = params;
    }

    public void setFieldsReader(DeviceMapper fieldsReader) {
        this.fieldsReader = fieldsReader;
    }

    public Collection<String> getColumnNames() {
        return fieldsReader.getColumnNames();
    }

    Flowable<Collection<String>> loadDevices() {
        final DeviceListCache.CacheTransaction transaction = deviceListCache.beginTransaction();
        return client
                .getDevices(params)
                .doOnNext(transaction::addDevice)
// Path: client/src/main/java/com/github/e13mort/stf/console/commands/cache/DeviceListCache.java
// public interface DeviceListCache {
//     static DeviceListCache getCache() {
//         return new DeviceListCacheImpl();
//     }
// 
//     DeviceListCache EMPTY = new DeviceListCache() {
//         @Override
//         public CacheTransaction beginTransaction() {
//             return CacheTransaction.EMPTY;
//         }
// 
//         @Override
//         public List<Device> getCachedFiles() {
//             return Collections.emptyList();
//         }
//     };
// 
//     CacheTransaction beginTransaction();
// 
//     List<Device> getCachedFiles();
// 
//     interface CacheTransaction {
//         CacheTransaction EMPTY = new CacheTransaction() {
//             @Override
//             public void addDevice(Device device) {
// 
//             }
// 
//             @Override
//             public void save() {
// 
//             }
//         };
// 
//         void addDevice(Device device);
// 
//         void save();
//     }
// }


// Path: client/src/main/java/com/github/e13mort/stf/console/commands/devices/DocumentsLoader.java
import com.github.e13mort.stf.client.FarmClient;
import com.github.e13mort.stf.client.parameters.DevicesParams;
import com.github.e13mort.stf.console.commands.cache.DeviceListCache;
import io.reactivex.Flowable;
import java.util.Collection;

package com.github.e13mort.stf.console.commands.devices;



class DocumentsLoader {

    private final FarmClient client;
    private final DevicesParams params;
    private DeviceMapper fieldsReader = DeviceMapper.EMPTY;
    private DeviceListCache deviceListCache = DeviceListCache.EMPTY;

    public DocumentsLoader(FarmClient client, DevicesParams params) {
        this.client = client;
        this.params = params;
    }

    public void setFieldsReader(DeviceMapper fieldsReader) {
        this.fieldsReader = fieldsReader;
    }

    public Collection<String> getColumnNames() {
        return fieldsReader.getColumnNames();
    }

    Flowable<Collection<String>> loadDevices() {
        final DeviceListCache.CacheTransaction transaction = deviceListCache.beginTransaction();
        return client
                .getDevices(params)
                .doOnNext(transaction::addDevice)
                .map(fieldsReader)