package example;

import java.io.IOException;
import java.util.List;

import groovy.lang.Binding;
import org.webharvest.runtime.processors.plugins.DbRowVariable;

import com.workfusion.odf.core.Intake;
import com.workfusion.rpa.core.plugin.PluginAdapterFactory;

public class Test {

    public static void main(Binding binding) throws IOException {

        final Intake intake = Intake.init(binding).get();
        final String DATASTORE_NAME = "datastore_name";
        final PluginAdapterFactory pluginAdapterFactory = intake.getInstance(PluginAdapterFactory.class);

        datastoreExample();
        datastoreTransactionalExample();
        secretVaultsExample(intake);
        s3Example(intake);

    }

    private static void s3Example(Intake intake) throws IOException {
        final S3pluginsExample s3pluginsExample = new S3pluginsExample(intake);
        s3pluginsExample.s3Example();
    }

    private static void secretVaultsExample(Intake intake) {
        SecretVaultsExample example = new SecretVaultsExample(intake);

        example.putIntoSecretsVaults();

        example.getFromSecretsVaults();

        example.deleteFromSecretsVaults();

        example.updateSecretsVaults();

        example.resetSecretsVaults();

        example.cleanUp();
    }

    private static void datastoreTransactionalExample() {
        // Executing examples

        DatastoreTransactionalExample datastoreTransactionalExample = new DatastoreTransactionalExample();

        datastoreTransactionalExample.createDatastore();

        datastoreTransactionalExample.insertRow();
        datastoreTransactionalExample.insertRow();
        datastoreTransactionalExample.insertRowsListOfRows();
        datastoreTransactionalExample.insertRowsListOfLists();

        final List<DbRowVariable> result = datastoreTransactionalExample.select();

        datastoreTransactionalExample.update();
        datastoreTransactionalExample.delete();
        datastoreTransactionalExample.transactionCommited();
        datastoreTransactionalExample.exceptionalExecution();
        datastoreTransactionalExample.transactionUncommited();
    }

    private static void datastoreExample() {
        // Executing examples
        DatastoreExample datastoreExample = new DatastoreExample();
        datastoreExample.createDatastore();

        datastoreExample.insertRow();
        datastoreExample.insertRow();
        datastoreExample.insertRowsListOfRows();
        datastoreExample.insertRowsListOfLists();
        final List<DbRowVariable> result = datastoreExample.select();

        datastoreExample.update();
        datastoreExample.delete();

        datastoreExample.exceptionalExecution();
    }

}
