package uk.ac.ebi.quickgo.rest.search.filter;

import uk.ac.ebi.quickgo.common.SearchableDocumentFields;

import com.google.common.base.Preconditions;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Takes care of providing {@link FieldExecutionConfig} instances for fields that are searchable via the provided
 * {@link SearchableDocumentFields} instance.
 *
 * @author Ricardo Antunes
 */
@Component
class InternalFilterExecutionConfig implements FilterExecutionConfig {
    private final Map<String, FieldExecutionConfig> executionConfigs;

    @Autowired
    public InternalFilterExecutionConfig(SearchableDocumentFields searchableDocumentFields) {
        Preconditions
                .checkArgument(searchableDocumentFields != null, "SearchableDocumentFields instance cannot be null.");

        executionConfigs = populateExecutionConfigs(searchableDocumentFields);
    }

    @Override public Optional<FieldExecutionConfig> getField(String fieldName) {
        Preconditions
                .checkArgument(fieldName != null && !fieldName.trim().isEmpty(), "Field name cannot be null or empty");
        return Optional.ofNullable(executionConfigs.get(fieldName));
    }

    private Map<String, FieldExecutionConfig> populateExecutionConfigs(SearchableDocumentFields
            searchableDocumentFields) {
        final FieldExecutionConfig.ExecutionType executionType = FieldExecutionConfig.ExecutionType.SIMPLE;

        return searchableDocumentFields.searchableDocumentFields()
                .map(field -> createFieldConfig(field, executionType))
                .collect(Collectors.toMap(FieldExecutionConfig::getName, Function.identity()));
    }

    private FieldExecutionConfig createFieldConfig(String fieldName, FieldExecutionConfig.ExecutionType type) {
        FieldExecutionConfig config = new FieldExecutionConfig();
        config.setName(fieldName);
        config.setExecution(type);

        return config;
    }
}
@@ -353,174 +353,355 @@
 t;%0A%0A
-/**%0A * Takes care of providing %7B@link FieldExecutionConfig%7D instances for fields that are searchable via the provided%0A * %7B@link SearchableDocumentFields%7D instance.%0A *
+import static uk.ac.ebi.quickgo.rest.search.filter.FieldExecutionConfig.*;%0A%0A/**%0A * This class contains the logic necessary to indicate how a field within the %7B@link SearchableDocumentFields%7D is to%0A * be searched.%0A * %3C/p%3E%0A * Fields declared in %7B@link SearchableDocumentFields%7D do not require any external processing configuration to be%0A * provided.
 %0A * 
@@ -738,17 +738,17 @@
 omponent
-%0A
+ 
 class In
@@ -1214,24 +1214,394 @@
 ds);%0A    %7D%0A%0A
+    /**%0A     * %7B@inheritDoc%7D%0A     *%0A     * If the %7B@param fieldName%7D is found to be searchable via %7B@link  SearchableDocumentFields%7D, then this method%0A     * will return a %7B@link FieldExecutionConfig%7D instance that indicates that the execution type will be%0A     * %7B@link ExecutionType#SIMPLE%7D.%0A     *%0A     * @param fieldName the name of the field%0A     * @return%0A     */%0A
     @Overrid
@@ -2027,117 +2027,8 @@
 ) %7B%0A
-        final FieldExecutionConfig.ExecutionType executionType = FieldExecutionConfig.ExecutionType.SIMPLE;%0A%0A
     
@@ -2145,17 +2145,17 @@
 (field, 
-e
+E
 xecution
@@ -2158,16 +2158,23 @@
 tionType
+.SIMPLE
 ))%0A     
@@ -2340,37 +2340,16 @@
 ldName, 
-FieldExecutionConfig.
 Executio

Improve Javadocs for the class and the getField method.