import uuid from 'uuid/v4'

class Manager {

	constructor() {
		this.id = Math.random();
		this.connections = [];
		this.circles = {};
	}

	addConnection(connection) {
		this.connections.push(connection)
	}

	pushEvent(type, data, id=null) {
		for (let connection of this.connections) {
			connection.sse(type, data,id);
		}
	}

	// add a circle
	addCircle(x, y, color) {

		let id = uuid();

		let data = {
			x : x,
			y : y,
			color : color
		};

		console.log(data);

		this.circles[id] = data;

		data.uuid = id;

		this.pushEvent('add', data);
	}

	removeCircle(id) {

		delete this.circles[id];

		this.pushEvent('delete', {
			uuid : id
		});
	}
}

var manager = new Manager()

export default manager;
