|  |  | @ -4,17 +4,21 @@ module Templates | 
			
		
	
		
		
			
				
					
					|  |  |  |   module CloneAttachments |  |  |  |   module CloneAttachments | 
			
		
	
		
		
			
				
					
					|  |  |  |     module_function |  |  |  |     module_function | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     def call(template:, original_template:) |  |  |  |     def call(template:, original_template:, documents: []) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |       schema_uuids_replacements = {} |  |  |  |       schema_uuids_replacements = {} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       cloned_schema = original_template.schema.deep_dup |  |  |  |       cloned_schema = original_template.schema.deep_dup | 
			
		
	
		
		
			
				
					
					|  |  |  |       cloned_fields = template.fields.deep_dup |  |  |  |       cloned_fields = template.fields.deep_dup | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       cloned_schema.each do |schema_item| |  |  |  |       cloned_schema.each_with_index do |schema_item, index| | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         new_schema_item_uuid = SecureRandom.uuid |  |  |  |         new_schema_item_uuid = SecureRandom.uuid | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         schema_uuids_replacements[schema_item['attachment_uuid']] = new_schema_item_uuid |  |  |  |         schema_uuids_replacements[schema_item['attachment_uuid']] = new_schema_item_uuid | 
			
		
	
		
		
			
				
					
					|  |  |  |         schema_item['attachment_uuid'] = new_schema_item_uuid |  |  |  |         schema_item['attachment_uuid'] = new_schema_item_uuid | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         new_name = documents&.dig(index, 'name') | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         schema_item['name'] = new_name if new_name.present? | 
			
		
	
		
		
			
				
					
					|  |  |  |       end |  |  |  |       end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       cloned_fields.each do |field| |  |  |  |       cloned_fields.each do |field| | 
			
		
	
	
		
		
			
				
					|  |  | 
 |