'use strict';

// MODULES //

var prefix = require( './stdlib.js' );
var hasOwnProp = require( prefix+'@stdlib/utils/has-own-property' );
var isObject = require( prefix+'@stdlib/utils/is-plain-object' );
var isString = require( prefix+'@stdlib/utils/is-string' ).isPrimitive;


// VALIDATE //

/**
* Validates function options.
*
* @private
* @param {Object} opts - destination object
* @param {Options} options - function options
* @param {string} [options.readme] - README filename
* @param {string} [options.index] - index filename
* @param {string} [options.title] - index title
* @param {string} [options.mount] - URL mount
* @param {Object} [options.tests] - tests options
* @param {string} [options.tests.pattern] - glob pattern
* @param {string} [options.tests.bundle] - bundle filename
* @param {string} [options.tests.folder] - folder name
* @param {string} [options.tests.html] - HTML filename
* @param {string} [options.tests.title] - HTML title
* @param {Object} [options.benchmarks] - benchmarks options
* @param {string} [options.benchmarks.pattern] - benchmarks glob pattern
* @param {string} [options.benchmarks.bundle] - bundle filename
* @param {string} [options.benchmarks.folder] - folder name
* @param {string} [options.benchmarks.html] - HTML filename
* @param {string} [options.benchmarks.title] - HTML title
* @returns {(Error|null)} error object or null
*
* @example
* var opts = {};
* var options = {
*     'readme': 'README.md',
*     'tests': {},
*     'benchmarks': {},
*     'html': {}
* };
*
* var err = validate( opts, options );
* if ( err ) {
*    throw err;
* }
*/
function validate( opts, options ) {
	if ( !isObject( options ) ) {
		return new TypeError( 'invalid input argument. Options argument must be an object. Value: `' + options +
			'`.' );
	}
	if ( hasOwnProp( options, 'readme' ) ) {
		opts.readme = options.readme;
		if ( !isString( opts.readme ) ) {
			return new TypeError( 'invalid option. `readme` option must be a string. Option: `'+opts.readme+'`.' );
		}
	}
	if ( hasOwnProp( options, 'index' ) ) {
		opts.index = options.index;
		if ( !isString( opts.index ) ) {
			return new TypeError( 'invalid option. `index` option must be a string. Option: `'+opts.index+'`.' );
		}
	}
	if ( hasOwnProp( options, 'title' ) ) {
		opts.title = options.title;
		if ( !isString( opts.title ) ) {
			return new TypeError( 'invalid option. `title` option must be a string. Option: `'+opts.title+'`.' );
		}
	}
	if ( hasOwnProp( options, 'mount' ) ) {
		opts.mount = options.mount;
		if ( !isString( opts.mount ) ) {
			return new TypeError( 'invalid option. `mount` option must be a string. Option: `'+opts.mount+'`.' );
		}
	}
	if ( hasOwnProp( options, 'tests' ) ) {
		if ( !isObject( opts.tests ) ) {
			return new TypeError( 'invalid option. `tests` option must be an object. Option: `'+opts.tests+'`.' );
		}
		if ( hasOwnProp( options.tests, 'pattern' ) ) {
			opts.tests.pattern = options.tests.pattern;
			if ( !isString( opts.tests.pattern ) ) {
				return new TypeError( 'invalid option. `tests.pattern` option must be a string. Option: `'+opts.tests.pattern+'`.' );
			}
		}
		if ( hasOwnProp( options.tests, 'folder' ) ) {
			opts.tests.folder = options.tests.folder;
			if ( !isString( opts.tests.folder ) ) {
				return new TypeError( 'invalid option. `tests.folder` option must be a string. Option: `'+opts.tests.folder+'`.' );
			}
		}
		if ( hasOwnProp( options.tests, 'bundle' ) ) {
			opts.tests.bundle = options.tests.bundle;
			if ( !isString( opts.tests.bundle ) ) {
				return new TypeError( 'invalid option. `tests.bundle` option must be a string. Option: `'+opts.tests.bundle+'`.' );
			}
		}
		if ( hasOwnProp( options.tests, 'html' ) ) {
			opts.tests.html = options.tests.html;
			if ( !isString( opts.tests.html ) ) {
				return new TypeError( 'invalid option. `tests.html` option must be a string. Option: `'+opts.tests.html+'`.' );
			}
		}
		if ( hasOwnProp( options.tests, 'title' ) ) {
			opts.tests.title = options.tests.title;
			if ( !isString( opts.tests.title ) ) {
				return new TypeError( 'invalid option. `tests.title` option must be a string. Option: `'+opts.tests.title+'`.' );
			}
		}
	}
	if ( hasOwnProp( options, 'benchmarks' ) ) {
		if ( !isObject( opts.benchmarks ) ) {
			return new TypeError( 'invalid option. `benchmarks` option must be an object. Option: `'+opts.benchmarks+'`.' );
		}
		if ( hasOwnProp( options.benchmarks, 'pattern' ) ) {
			opts.benchmarks.pattern = options.benchmarks.pattern;
			if ( !isString( opts.benchmarks.pattern ) ) {
				return new TypeError( 'invalid option. `benchmarks.pattern` option must be a string. Option: `'+opts.benchmarks.pattern+'`.' );
			}
		}
		if ( hasOwnProp( options.benchmarks, 'folder' ) ) {
			opts.benchmarks.folder = options.benchmarks.folder;
			if ( !isString( opts.benchmarks.folder ) ) {
				return new TypeError( 'invalid option. `benchmarks.folder` option must be a string. Option: `'+opts.benchmarks.folder+'`.' );
			}
		}
		if ( hasOwnProp( options.benchmarks, 'bundle' ) ) {
			opts.benchmarks.bundle = options.benchmarks.bundle;
			if ( !isString( opts.benchmarks.bundle ) ) {
				return new TypeError( 'invalid option. `benchmarks.bundle` option must be a string. Option: `'+opts.benchmarks.bundle+'`.' );
			}
		}
		if ( hasOwnProp( options.benchmarks, 'html' ) ) {
			opts.benchmarks.html = options.benchmarks.html;
			if ( !isString( opts.benchmarks.html ) ) {
				return new TypeError( 'invalid option. `benchmarks.html` option must be a string. Option: `'+opts.benchmarks.html+'`.' );
			}
		}
		if ( hasOwnProp( options.benchmarks, 'title' ) ) {
			opts.benchmarks.title = options.benchmarks.title;
			if ( !isString( opts.benchmarks.title ) ) {
				return new TypeError( 'invalid option. `benchmarks.title` option must be a string. Option: `'+opts.benchmarks.title+'`.' );
			}
		}
	}
	return null;
} // end FUNCTION validate()


// EXPORTS //

module.exports = validate;

@@ -1492,26 +1492,8 @@
 ks':
- %7B%7D,%0A*     'html':
  %7B%7D%0A

Remove old option