// helpers/deduplicate.ts
import { INodeProperties } from 'n8n-workflow';

/**
 * Adds descriptions to a target array, avoiding duplicates
 *
 * @param target The target array to add descriptions to
 * @param source The source array of descriptions to add
 */
export function addDescriptions(
	target: INodeProperties[],
	source: INodeProperties[] | undefined,
): void {
	if (!Array.isArray(source) || source.length === 0) return;

	source.forEach((item) => {
		const exists = target.some(
			(existing) =>
				existing.name === item.name &&
				existing.type === item.type &&
				JSON.stringify(existing.displayOptions) === JSON.stringify(item.displayOptions),
		);

		if (!exists) {
			target.push(item);
		}
	});
}
