/**
 * @module utils/playerUtils
 */

import cond from 'lodash/cond';
import assign from 'lodash/assign';
import isUndefined from 'lodash/isUndefined'
import { stubTrue as otherwise } from 'lodash/stubTrue';
import concat from 'lodash/concat';
import { common, corePlugins } from "../players/config";
import { yell } from "./common";


const has = key => opt => isUndefined(opt[key]);
const hasWrapperEvents = has('wrapperEvents');
const mergeDeviceConfig = opt => assign({}, common, opt, { plugins: concat(opt.plugins || [], corePlugins) });
/**
 * merge player options with the common options
 * @author Aamir khan
 * @param {Object} options config from the player
 * @returns {Object} updated config with device and common config
 */
export const mergeWithCommon = cond([
    [hasWrapperEvents, yell(`wrapperEvents is missing make sure to pass wrapperEvents in the options`)],
    [otherwise, mergeDeviceConfig]
]);