package fi.evident.apina.model.settings;

import fi.evident.apina.utils.PatternSet;

import java.util.Collection;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Collections.unmodifiableCollection;

/**
 * Various settings guiding the translation.
 */
public final class TranslationSettings {

    public final PatternSet blackBoxClasses = new PatternSet();
    private final TreeMap<String, ImportDefinition> importsByModule = new TreeMap<>();
    private final Set<String> importedTypes = new TreeSet<>();

    public boolean isBlackBoxClass(String name) {
        return blackBoxClasses.test(name);
    }

    public void addImport(String typeName, String moduleName) {
        if (!importedTypes.add(typeName))
            throw new IllegalArgumentException("type " + typeName + " is already imported");

        importsByModule.computeIfAbsent(moduleName, ImportDefinition::new).addType(typeName);
    }

    public Collection<ImportDefinition> getImports() {
        return unmodifiableCollection(importsByModule.values());
    }

    public boolean isImported(String typeName) {
        return importedTypes.contains(typeName);
    }
}

@@ -690,39 +690,201 @@
 ing 
-typ
+modul
 eName, 
-String moduleName) %7B%0A
+Collection%3CString%3E types) %7B%0A        ImportDefinition importDefinition = importsByModule.computeIfAbsent(moduleName, ImportDefinition::new);%0A%0A        for (String type : types) %7B%0A    
     
@@ -918,15 +918,15 @@
 type
-Name))%0A
+))%0A    
     
@@ -982,20 +982,16 @@
 %22 + type
-Name
  + %22 is 
@@ -1023,53 +1023,13 @@
     
-importsByModule.computeIfAbsent(moduleName, I
+    i
 mpor
@@ -1039,22 +1039,16 @@
 finition
-::new)
 .addType
@@ -1048,30 +1048,36 @@
 addType(type
-Name);
+);%0A        %7D
 %0A    %7D%0A%0A    

Allow multiple types to be imported with single call