{"size": 809, "ext": "js", "max_stars_repo_path": "lib/lights.js", "max_stars_repo_name": "schroffl/node-huebridge", "max_stars_repo_stars_event_min_datetime": "2019-07-28T14:55:40.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-28T14:55:40.000Z", "max_issues_repo_path": "lib/lights.js", "max_issues_repo_name": "schroffl/node-huebridge", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/lights.js", "max_forks_repo_name": "schroffl/node-huebridge", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.4722222222, "max_line_length": 61, "alphanum_fraction": 0.5673671199}
'use strict';

const state = require('./state');
const deepAssign = require('deep-assign');
const idGenerator = require('./idgen');

module.exports = () => {
	let lights = { },
		idGen = idGenerator(id => !(id in lights));

	let wrapper = {
		'create': config => {
			let id = idGen.next().value,
				light = Object.assign({ 
					id,
					'name': 'Light ' + id,
					'state': state(),
					'type': 'Extended color light',
					'modelid': 'LCT010',
					'swversion': '66009461',
					'update': obj => deepAssign(light, obj)
				}, config);

			lights[id] = Object.assign(light, wrapper.factory(light));

			return light;
		},
		'get': id => lights[id],
		'delete': id => delete lights[id],
		'list': () => Object.assign({ }, lights),
		'factory': light => ({ }),
		'reference': lights
	};

	return wrapper;
};