package collections

// MergeMaps is a function that is authored (except the name) by Copilot.
func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V {
	result := make(map[K]V)
	for _, m := range maps {
		for k, v := range m {
			result[k] = v
		}
	}
	return result
}

// DeepCopyMap returns a deep copy of the given map.
// Note: the map's value cannot be a reference type (like slice or map).
func DeepCopyMap[K comparable, V any](originalMap map[K]V) map[K]V {
	// Create a new map to store the copied key-value pairs with the same capacity as the original map
	copiedMap := make(map[K]V, len(originalMap))

	// Iterate over the original map's key-value pairs
	for key, value := range originalMap {
		// Add the key-value pair into the new map, since the value is not a reference type, it is safe to copy directly
		copiedMap[key] = value
	}

	// Return the deep copied map
	return copiedMap
}
