/*
 * Copyright 2015 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

package com.hp.autonomy.searchcomponents.idol.search.fields;

import com.hp.autonomy.frontend.configuration.ConfigService;
import com.hp.autonomy.searchcomponents.core.config.FieldInfo;
import com.hp.autonomy.searchcomponents.core.config.FieldType;
import com.hp.autonomy.searchcomponents.core.config.HavenSearchCapable;
import com.hp.autonomy.searchcomponents.core.fields.FieldPathNormaliser;
import com.hp.autonomy.searchcomponents.core.search.fields.AbstractDocumentFieldsService;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Collection;

import static com.hp.autonomy.searchcomponents.core.search.fields.DocumentFieldsService.DOCUMENT_FIELDS_SERVICE_BEAN_NAME;

@Getter
@SuppressWarnings("InstanceVariableOfConcreteClass")
@Component(DOCUMENT_FIELDS_SERVICE_BEAN_NAME)
class IdolDocumentFieldsServiceImpl extends AbstractDocumentFieldsService implements IdolDocumentFieldsService {
    static final String QMS_ID_FIELD = "QMSID";
    static final String INJECTED_PROMOTION_FIELD = "INJECTEDPROMOTION";
    private final FieldInfo<String> qmsIdFieldInfo;
    private final FieldInfo<Boolean> injectedPromotionFieldInfo;

    @SuppressWarnings("TypeMayBeWeakened")
    @Autowired
    IdolDocumentFieldsServiceImpl(final ConfigService<? extends HavenSearchCapable> configService,
                                  final FieldPathNormaliser fieldPathNormaliser) {
        super(configService);

        qmsIdFieldInfo = FieldInfo.<String>builder()
                .name(fieldPathNormaliser.normaliseFieldPath(QMS_ID_FIELD))
                .advanced(true)
                .build();

        injectedPromotionFieldInfo = FieldInfo.<Boolean>builder()
                .name(fieldPathNormaliser.normaliseFieldPath(INJECTED_PROMOTION_FIELD))
                .type(FieldType.BOOLEAN)
                .advanced(true)
                .build();
    }

    @Override
    public Collection<FieldInfo<?>> getHardCodedFields() {
        return Arrays.asList(qmsIdFieldInfo, injectedPromotionFieldInfo);
    }
}

@@ -1323,110 +1323,366 @@
     
-private final FieldInfo%3CString%3E qmsIdFieldInfo;%0A    private final FieldInfo%3CBoolean%3E injectedPromotion
+static final String FACT_ID_FIELD = %22FACTS/FACT_EXTRACT_/ID%22;%0A    static final String FACT_SENTENCE_FIELD = %22FACTS/FACT_EXTRACT_/SENTENCE%22;%0A    private final FieldInfo%3CString%3E qmsIdFieldInfo;%0A    private final FieldInfo%3CBoolean%3E injectedPromotionFieldInfo;%0A    private final FieldInfo%3CString%3E factIdFieldInfo;%0A    private final FieldInfo%3CString%3E factSentence
 Fiel
@@ -2400,16 +2400,452 @@
 build();
+%0A%0A        factIdFieldInfo = FieldInfo.%3CString%3Ebuilder()%0A            .id(FACT_ID_FIELD)%0A            .name(fieldPathNormaliser.normaliseFieldPath(FACT_ID_FIELD))%0A            .advanced(true)%0A            .build();%0A%0A        factSentenceFieldInfo = FieldInfo.%3CString%3Ebuilder()%0A            .id(FACT_SENTENCE_FIELD)%0A            .name(fieldPathNormaliser.normaliseFieldPath(FACT_SENTENCE_FIELD))%0A            .advanced(true)%0A            .build();
 %0A    %7D%0A%0A
@@ -2946,16 +2946,29 @@
 .asList(
+%0A            
 qmsIdFie
@@ -3001,16 +3001,56 @@
 ieldInfo
+, factIdFieldInfo, factSentenceFieldInfo
 );%0A    %7D

add default field configuration for facts fields