/* eslint-disable no-console */
/**
 * this module contains helpers which are only to be use in development mode
* every function define in this file must wrap all the code in a development check env for dead code elimination
* see `template` function for better understanding
    @module utils/devOnly
    @author Aamir khan
*/





import forEach from 'lodash/forEach';
import isArray from 'lodash/isArray';
import isFunction from 'lodash/isFunction';
import isObject from 'lodash/isObject';
import noop from "lodash/noop";



// use below function as template only
// eslint-disable-next-line no-unused-vars
const template = () => {
    if (process.env.NODE_ENV === 'development') {
        // your code goes here
    }
};


/**
 * @author Aamir khan
 * @desc while working on a module/bug we always need to log something then add
 * filters to the console to figure out which log is ours
 * this HOF will make it easy to do that
 * and it will be silent in build
 * @param {String} label - lable for the logger to show in console
 *
 * @example
 * const log = makeLog('AYSW')
 *
 * /// now use it anywhere like a log
 *
 * log('setting up events') 👉 AYSW setting up events
 */

export const makeLog = (label) => {
    // TODO(iamaamir): add config to make it silent
    // if (process.env.NODE_ENV === 'development') {
    //     // eslint-disable-next-line no-console
    //     return console.log.bind(console, `%c ${label}`, 'background: #000; color: #bada55');
    // }
    return noop
};


const log = makeLog("DEV-ONLY");
export const validatePlugins = (plugins) => {
    if (process.env.NODE_ENV === 'development') {
        log('validating plugins');
        const api = ['setup', 'onload', 'destroy'];
        if (!plugins) {
            return;
        }
        if (!isArray(plugins) || plugins.length === 0) {
            throw new Error("plugins must be an array");
        }
        forEach(plugins, (plugin) => {
            if (!isObject(plugin)) {
                throw new Error("plugins must be an array of Objects");
            }

            if (!plugin.name) {
                throw new Error("plugin must have a name");
            }

            forEach(api, method => {
                if (!isFunction(plugin[method])) {
                    throw new Error(`plugin ${plugin.name} must have a ${method} method`);
                }
            });

        });
    }

}