/*!
 * 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.
 */
import emptyModel from './emptyModel.json';

function mergeLifelines(oldLifelines, newLifelines) {
	let oldLifelinesMap = new Map(oldLifelines.map(lifeline => [lifeline.id, lifeline]));
	let newLifelinesMap = new Map(newLifelines.map(lifeline => [lifeline.id, lifeline]));

	let updatedLifelines = oldLifelines.map(lifeline => {
		let newLifeline = newLifelinesMap.get(lifeline.id);
		return {
			...lifeline,
			name: newLifeline ? newLifeline.name : lifeline.name
		};
	});

	let addedLifelines = newLifelines.filter(lifeline => !oldLifelinesMap.has(lifeline.id));

	return [
		...updatedLifelines,
		...addedLifelines
	];
}


const SequenceDiagramModelHelper = Object.freeze({

	createModel(options) {
		return SequenceDiagramModelHelper.updateModel(emptyModel, options);
	},

	updateModel(model, options) {
		const diagram = model.diagram;
		const metadata = diagram.metadata || model.metadata;
		const id = options.id || metadata.id;
		const name = options.name || metadata.name;
		const lifelines = options.lifelines ? mergeLifelines(diagram.lifelines, options.lifelines) : diagram.lifelines;

		return {
			diagram: {
				...diagram,
				metadata: {
					...metadata,
					id,
					name
				},
				lifelines
			}
		};
	}
});

export default SequenceDiagramModelHelper;
