/*!
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
var keyMirror = function (obj) {
	var ret = {};
	var key;
	var val;
	if (!(obj instanceof Object && !Array.isArray(obj))) {
		throw new Error('keyMirror(...): Argument must be an object.');
	}
	for (key in obj) {
		if (obj.hasOwnProperty(key)) {
			val = obj[key];
			if (val instanceof Object) {
				ret[key] = keyMirror(obj[key]);
			} else if(val !== null && val !== undefined){
				ret[key] = val;
			}
			else {
				ret[key] = Symbol(key);
			}
		}
	}
	return Object.freeze(ret);
};

export default keyMirror;