"use strict";

var SharedConstants = require("../../../shared/constants/SharedConstants");
var UtilElasticSearch = require("../../utils/UtilElasticSearch");
var dbConfig = require('./DatabaseConfig');

module.exports = function(connectionName) {

    var provider;
    global.currentConnectionName =  connectionName;
    var providerName = dbConfig.getDataServicesConfig(connectionName).providerName;

    if (providerName) { 
        var providerPath = "./" + providerName.toLowerCase();

        // this will require the objects exported from the index.js of the provider
        //provider = require(providerPath);
       provider = require('../dataServices');
       global.DBProvider =  require(providerPath);
    } else {
        throw new Error("Provider name not specified in database configuration");
    }

    return provider;
};