{"size": 1092, "ext": "js", "max_stars_repo_path": "src/provider/providerManager.js", "max_stars_repo_name": "hugo-cardenas/video-backupper", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/provider/providerManager.js", "max_issues_repo_name": "hugo-cardenas/video-backupper", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/provider/providerManager.js", "max_forks_repo_name": "hugo-cardenas/video-backupper", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.75, "max_line_length": 67, "alphanum_fraction": 0.6043956044}
var VError = require('verror');
var baserequire = require('base-require');
var createProvider = baserequire('src/provider/provider');

/**
 * @typedef {Object} ProviderManager
 *
 * @property {function} getProvider Get provider object
 */

/**
 * @param {Object} google Google client object
 * @param {Config} config Config object
 * @returns {ProviderManager}
 */
module.exports = function (google, config) {
    const PROVIDER_CONFIG = 'provider.youtube';

    var provider;

    /**
     * @returns {Provider}
     * @throws {Error} If config is invalid
     */
    function getProvider() {
        if (!provider) {
            provider = createProvider(google, getProviderConfig());
        }
        return provider;
    }

    /**
     * @returns {Object} Plain config Object
     * @throws {Error} If config is invalid
     */
    function getProviderConfig() {
        try {
            return config.get(PROVIDER_CONFIG);
        } catch (err) {
            throw new VError(err, 'Unable to create provider');
        }
    }

    return {
        getProvider: getProvider
    };
};
