package uk.ac.ebi.quickgo.annotation.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import uk.ac.ebi.quickgo.annotation.download.converter.AnnotationToGAF;
import uk.ac.ebi.quickgo.annotation.download.converter.AnnotationToGPAD;
import uk.ac.ebi.quickgo.annotation.download.converter.AnnotationToTSV;
import uk.ac.ebi.quickgo.annotation.download.http.GAFHttpMessageConverter;
import uk.ac.ebi.quickgo.annotation.download.http.GPADHttpMessageConverter;
import uk.ac.ebi.quickgo.annotation.download.http.TSVHttpMessageConverter;
import uk.ac.ebi.quickgo.rest.controller.response.NoFacetNoHighlightNoAggregateQueryResult;
import uk.ac.ebi.quickgo.rest.controller.response.NoNextCursorPageInfo;
import uk.ac.ebi.quickgo.rest.search.results.PageInfo;
import uk.ac.ebi.quickgo.rest.search.results.QueryResult;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Configures how the response to the client should be handled.
 *
 * @author Ricardo Antunes
 */
@Configuration class ResponseConfig {
    @Primary
    @Bean
    static ObjectMapper objectMapper() {
        ObjectMapper mapper = new ObjectMapper();
        Map<Class<?>, Class<?>> mixinMap = new HashMap<>();
        mixinMap.put(QueryResult.class, NoFacetNoHighlightNoAggregateQueryResult.class);
        mixinMap.put(PageInfo.class, NoNextCursorPageInfo.class);
        mapper.setMixIns(Collections.unmodifiableMap(mixinMap));
        return mapper;
    }

    @Bean
    public GPADHttpMessageConverter gpadHttpMessageConverter() {
        return new GPADHttpMessageConverter(gpadAnnotationConverter());
    }

    @Bean
    public GAFHttpMessageConverter gafHttpMessageConverter() {
        return new GAFHttpMessageConverter(gafAnnotationConverter());
    }

    @Bean
    public TSVHttpMessageConverter tsvHttpMessageConverter(){
        return new TSVHttpMessageConverter(annotationToTSV());
    }

    private AnnotationToGPAD gpadAnnotationConverter() {
        return new AnnotationToGPAD();
    }

    private AnnotationToGAF gafAnnotationConverter() {
        return new AnnotationToGAF();
    }

    private AnnotationToTSV annotationToTSV(){
        return new AnnotationToTSV();
    }
}

@@ -534,182 +534,9 @@
 ttp.
-GAFHttpMessageConverter;%0Aimport uk.ac.ebi.quickgo.annotation.download.http.GPADHttpMessageConverter;%0Aimport uk.ac.ebi.quickgo.annotation.download.http.TSVHttpMessageConverter
+*
 ;%0Aim
@@ -888,16 +888,93 @@
 til.Map;
+%0Aimport static uk.ac.ebi.quickgo.annotation.download.http.MediaTypeFactory.*;
 %0A%0A/**%0A *
@@ -1553,19 +1553,22 @@
 public G
-PAD
+eneric
 HttpMess
@@ -1629,19 +1629,22 @@
 rn new G
-PAD
+eneric
 HttpMess
@@ -1656,20 +1656,20 @@
 nverter(
-gpad
+new 
 Annotati
@@ -1666,35 +1666,49 @@
 w Annotation
-Converter()
+ToGPAD(), GPAD_MEDIA_TYPE
 );%0A    %7D%0A%0A  
@@ -1727,18 +1727,22 @@
 public G
-AF
+eneric
 HttpMess
@@ -1802,18 +1802,22 @@
 rn new G
-AF
+eneric
 HttpMess
@@ -1829,19 +1829,20 @@
 nverter(
-gaf
+new 
 Annotati
@@ -1843,27 +1843,39 @@
 notation
-Converter()
+ToGAF(), GAF_MEDIA_TYPE
 );%0A    %7D
@@ -1897,19 +1897,23 @@
  public 
-TSV
+Generic
 HttpMess
@@ -1971,19 +1971,23 @@
 urn new 
-TSV
+Generic
 HttpMess
@@ -2003,327 +2003,56 @@
 ter(
-annotationToTSV());%0A    %7D%0A%0A    private AnnotationToGPAD gpadAnnotationConverter() %7B%0A        return new AnnotationToGPAD();%0A    %7D%0A%0A    private AnnotationToGAF gafAnnotationConverter() %7B%0A        return new AnnotationToGAF();%0A    %7D%0A%0A    private AnnotationToTSV annotationToTSV()%7B%0A        return new AnnotationToTSV();
+new AnnotationToTSV(), TSV_MEDIA_TYPE);%0A    %7D
 %0A    %7D%0A
-%7D%0A

Replace individual message converters with GenericHttpMessageConverter.