"use strict";

function invertMapping(mapping) {
	let invertedMapping = {};

	for (let [ key, values ] of Object.entries(mapping)) {
		for (let value of values) {
			if (invertedMapping[value] == null) {
				invertedMapping[value] = [];
			}

			invertedMapping[value].push(key);
		}
	}

	return invertedMapping;
}

module.exports = function mapDirectEvent(event, _context) {
	// Context: account data
	
	return {
		type: "directMessageRoomsChanged",
		userToRooms: event.content,
		roomToUsers: invertMapping(event.content)
	};
};
