/*
 * 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.
 */

package com.teradata.tempto.internal.configuration;

import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.teradata.tempto.configuration.Configuration;
import com.teradata.tempto.initialization.AutoModuleProvider;
import com.teradata.tempto.initialization.SuiteModuleProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Optional;

import static com.google.inject.name.Names.named;

@AutoModuleProvider
public class TestConfigurationModuleProvider
        implements SuiteModuleProvider
{

    private static final Logger LOGGER = LoggerFactory.getLogger(TestConfigurationModuleProvider.class);

    @Override
    public Module getModule(Configuration configuration)
    {
        return new AbstractModule()
        {
            @Override
            protected void configure()
            {
                bind(Configuration.class).toInstance(configuration);
                bindConfigurationKeys();
            }

            private void bindConfigurationKeys()
            {
                for (String key : configuration.listKeys()) {
                    Optional<Object> value = configuration.get(key);
                    if (value.isPresent()) {
                        @SuppressWarnings("unchecked") Class<Object> valueClass = (Class<Object>) value.get().getClass();

                        LOGGER.debug("Binding {} key: {} -> {}", valueClass.getName(), key, value.get());

                        bind(valueClass)
                                .annotatedWith(named(key))
                                .toInstance(value.get());
                    }
                }
            }
        };
    }
}

@@ -675,22 +675,90 @@
 .inject.
-Module
+Key;%0Aimport com.google.inject.Module;%0Aimport com.google.inject.TypeLiteral
 ;%0Aimport
@@ -990,16 +990,39 @@
 ctory;%0A%0A
+import java.util.List;%0A
 import j
@@ -1926,51 +1926,39 @@
 d%22) 
-Class%3CObject%3E valueClass = (Class%3CObject%3E) 
+Key bindingKey = getBindingKey(
 valu
@@ -1968,18 +1968,13 @@
 et()
-.getClass(
+, key
 );%0A%0A
@@ -2042,28 +2042,18 @@
 %7D%22, 
-valueClass.getName()
+bindingKey
 , ke
@@ -2103,19 +2103,77 @@
 ind(
-valueClass)
+bindingKey)%0A                                .toInstance(value.get());
 %0A   
@@ -2180,32 +2180,35 @@
                 
+ %7D%0A
              .an
@@ -2208,34 +2208,104 @@
     
-.annotatedWith(named(k
+   %7D%0A            %7D%0A%0A            private  Key getBindingKey(Object configValue, String configK
 ey)
-)
 %0A   
@@ -2317,50 +2317,214 @@
     
-                    .toInstance(value.get(
+%7B%0A                if (configValue instanceof List) %7B%0A                    // currently only list of strings is supported%0A                    return Key.get(new TypeLiteral%3CList%3CString%3E%3E() %7B%7D, named(configKey
 ));%0A
@@ -2531,36 +2531,32 @@
                 
-    
 %7D%0A              
@@ -2549,33 +2549,89 @@
                 
-%7D
+return Key.get(configValue.getClass(), named(configKey));
 %0A            %7D%0A 
@@ -2621,32 +2621,33 @@
 ;%0A            %7D%0A
+%0A
         %7D;%0A    %7D
@@ -2647,10 +2647,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Fix binding List<String> in TestConfigurationModuleProvider