package example;

import java.util.Optional;

import com.freedomoss.crowdcontrol.webharvest.web.dto.SecureEntryDTO;
import org.slf4j.Logger;

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

import static com.workfusion.rpa.core.plugin.PluginAdapterFactory.PluginsEnum.SECRETS_VAULT;

public class SecretVaultsExample {

    private static final SecretsVaultPluginAdapter secretsVaultPluginAdapter = PluginAdapterFactory.getInstance().getPluginAdapter(SECRETS_VAULT);
    private static final String ALIAS = "smbuser";
    private static final String USERNAME = "some cool username";
    private static final String SECURE_PSWD = "secure password";
    private static final String ALIAS_TO_UPDATE = "some alias to update**";
    private static final String USERNAME_TO_BE_UPDATED = "some cool username to be updated";
    private static final String PSWD_TO_BE_UPDATED = "secure password to be updated";
    private static final String ALIAS_TO_DELETE = "some alias to delete**";
    private static final String USERNAME_TO_BE_DELETED = "some cool username to be deleted";
    private static final String PSWD_TO_BE_DELETED = "secure password to be deleted";
    private static final String NEW_UPDATED_PSWD = "new updated password";
    private static final String NEW_UPDATED_USERNAME =     "new updated username";
    private final Logger log;

    public SecretVaultsExample(Intake intake) {
        this.log = intake.getInstance(Logger.class);
    }

    public void putIntoSecretsVaults(){
        final Boolean putSecretsVaultVariable = secretsVaultPluginAdapter.putSecretsVault(ALIAS, USERNAME, SECURE_PSWD);
        final Boolean putSecretsVaultVariable1 = secretsVaultPluginAdapter.putSecretsVault(ALIAS_TO_DELETE, USERNAME_TO_BE_DELETED, PSWD_TO_BE_DELETED);
        final Boolean putSecretsVaultVariable2 = secretsVaultPluginAdapter.putSecretsVault(ALIAS_TO_UPDATE, USERNAME_TO_BE_UPDATED, PSWD_TO_BE_UPDATED);

    }

    public void getFromSecretsVaults(){
        final Optional<SecureEntryDTO> getSecretsVault = secretsVaultPluginAdapter.getSecretsVault(ALIAS);
        final Optional<SecureEntryDTO> getSecretsVault1 = secretsVaultPluginAdapter.getSecretsVault(ALIAS_TO_DELETE);
        final Optional<SecureEntryDTO> getSecretsVault2 = secretsVaultPluginAdapter.getSecretsVault(ALIAS_TO_UPDATE);

    }



    public void deleteFromSecretsVaults(){
        final Boolean deleteFromSecretsVaultVariable = secretsVaultPluginAdapter.deleteFromSecretsVault(ALIAS_TO_DELETE);
    }

    public void updateSecretsVaults(){
        final Boolean updateSecretsVaultVariable = secretsVaultPluginAdapter.updateSecretsVault(ALIAS_TO_UPDATE, NEW_UPDATED_USERNAME, NEW_UPDATED_PSWD);
    }

    public void resetSecretsVaults(){
        final Boolean secretsVaultPluginAdapterVariable = secretsVaultPluginAdapter.resetSecretsVault(ALIAS_TO_UPDATE);
    }

    public void cleanUp(){
        secretsVaultPluginAdapter.deleteFromSecretsVault(ALIAS_TO_UPDATE);
        secretsVaultPluginAdapter.deleteFromSecretsVault(ALIAS);
    }
}
