package com.bitdubai.fermat_cry_plugin.layer.crypto_network.bitcoin.developer.bitdubai.version_1;

import com.bitdubai.fermat_api.Plugin;
import com.bitdubai.fermat_api.Service;
import com.bitdubai.fermat_api.layer.dmp_world.wallet.exceptions.CantStartAgentException;
import com.bitdubai.fermat_api.layer.all_definition.enums.ServiceStatus;
import com.bitdubai.fermat_cry_api.layer.crypto_network.bitcoin.BitcoinCryptoNetworkManager;
import com.bitdubai.fermat_cry_api.layer.crypto_vault.CryptoVault;
import com.bitdubai.fermat_cry_plugin.layer.crypto_network.bitcoin.developer.bitdubai.version_1.structure.BitcoinCryptoNetworkMonitoringAgent;
import org.bitcoinj.core.Wallet;

import java.util.UUID;

/**
 * Created by ciencias on 20.01.15.
 */

/**
 * This plugin interfaces the bitcoin network. It primary mission is to hold the bitcoins for each user on this device.
 * 
 * It handles a bitcoin wallet for each user process transactions upon request from other plugins.
 * 
 * It also monitors the bitcoin network for incoming transactions for any of the device's users.
 * 
 * 
 * * * * * * * *
 */

public class BitcoinCryptoNetworkPluginRoot implements BitcoinCryptoNetworkManager, Service, Plugin{

    /**
     * BitcoinCryptoNetworkManager interface member variables
     */
    CryptoVault cryptoVault;
    BitcoinCryptoNetworkMonitoringAgent bitcoinCryptoNetworkMonitoringAgent;

    /**
     * Service Interface member variables.
     */
    ServiceStatus serviceStatus = ServiceStatus.CREATED;

    /**
     * PlatformService Interface implementation.
     */

    @Override
    public void start() {
        this.serviceStatus = ServiceStatus.STARTED;
    }

    @Override
    public void pause() {

        this.serviceStatus = ServiceStatus.PAUSED;

    }


    @Override
    public void resume() {

        this.serviceStatus = ServiceStatus.STARTED;

    }

    @Override
    public void stop() {
        this.serviceStatus = ServiceStatus.STOPPED;
    }

    @Override
    public ServiceStatus getStatus() {
        return serviceStatus;
    }

    /**
     * Plugin interface implementation
     * @param uuid
     */
    @Override
    public void setId(UUID uuid) {
    }

    @Override
    public void setVault(CryptoVault cryptoVault) {
        this.cryptoVault = cryptoVault;
    }

    @Override
    public void connectToBitcoinNetwork() {
        bitcoinCryptoNetworkMonitoringAgent = new BitcoinCryptoNetworkMonitoringAgent((Wallet) cryptoVault.getWallet(), cryptoVault.getUserId());
        try {
            bitcoinCryptoNetworkMonitoringAgent.start();
        } catch (CantStartAgentException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void disconnectFromBitcoinNetwork() {
        bitcoinCryptoNetworkMonitoringAgent.stop();
    }

    @Override
    public Object getBroadcasters() {
        return bitcoinCryptoNetworkMonitoringAgent.getPeers();
    }
}
@@ -92,16 +92,72 @@
 ion_1;%0A%0A
+import com.bitdubai.fermat_api.DealsWithPluginIdentity;%0A
 import c
@@ -390,16 +390,358 @@
 Status;%0A
+import com.bitdubai.fermat_api.layer.osa_android.file_system.DealsWithPluginFileSystem;%0Aimport com.bitdubai.fermat_api.layer.osa_android.file_system.PluginFileSystem;%0Aimport com.bitdubai.fermat_api.layer.pip_platform_service.error_manager.DealsWithErrors;%0Aimport com.bitdubai.fermat_api.layer.pip_platform_service.error_manager.ErrorManager;%0A
 import c
@@ -1579,16 +1579,85 @@
 Manager,
+ DealsWithErrors, DealsWithPluginIdentity, DealsWithPluginFileSystem,
  Service
@@ -1871,108 +1871,1074 @@
   * 
-Service Interface member variables.%0A     */%0A    ServiceStatus serviceStatus = ServiceStatus.CREATED;
+DealsWithErrors interface member variables%0A     */%0A    ErrorManager errorManager;%0A%0A    /**%0A     * DealsWithPluginIdentity interface member variable%0A     */%0A    UUID pluginId;%0A%0A    /**%0A     * DealswithPluginFileSystem interface member variable%0A     */%0A    PluginFileSystem pluginFileSystem;%0A%0A    /**%0A     * Service Interface member variables.%0A     */%0A    ServiceStatus serviceStatus = ServiceStatus.CREATED;%0A%0A%0A    /**%0A     * DealsWithError interface implementation%0A     * @param errorManager%0A     */%0A    @Override%0A    public void setErrorManager(ErrorManager errorManager) %7B%0A        this.errorManager = errorManager;%0A    %7D%0A%0A    /**%0A     * DealsWithPluginIdentity interface implementation%0A     * @param pluginId%0A     */%0A    @Override%0A    public void setPluginId(UUID pluginId) %7B%0A        this.pluginId = pluginId;%0A    %7D%0A%0A    /**%0A     * DealsWithPluginFileSystem interface implementation%0A      * @param pluginFileSystem%0A     */%0A    @Override%0A    public void setPluginFileSystem(PluginFileSystem pluginFileSystem) %7B%0A        this.pluginFileSystem = pluginFileSystem;%0A    %7D
 %0A%0A  
@@ -3938,16 +3938,242 @@
 rId());%0A
+        bitcoinCryptoNetworkMonitoringAgent.setPluginFileSystem(pluginFileSystem);%0A        bitcoinCryptoNetworkMonitoringAgent.setErrorManager(errorManager);%0A        bitcoinCryptoNetworkMonitoringAgent.setPluginId(pluginId);%0A%0A
         

correct right usage of DealsWith in BitcoinManager