package uk.ac.ebi.atlas.search.analyticsindex.baseline;

import com.jayway.jsonpath.JsonPath;
import uk.ac.ebi.atlas.search.SemanticQuery;
import uk.ac.ebi.atlas.search.analyticsindex.solr.AnalyticsQueryClient;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
import java.util.Map;

@Named
public class BaselineAnalyticsSearchDao {

    //TODO no need for a filter there
    public static final String EXPERIMENTS_PATH = "$.facets.experimentType.buckets[?(@.val=='RNASEQ_MRNA_BASELINE' ||" +
            " @.val=='PROTEOMICS_BASELINE')]..experimentAccession.buckets[*]";
    static final String FACET_TREE_PATH = "$.facets.experimentType.buckets[?(@.val=='RNASEQ_MRNA_BASELINE' || @.val=='PROTEOMICS_BASELINE')].species.buckets[*]";

    private final AnalyticsQueryClient analyticsQueryClient;

    @Inject
    public BaselineAnalyticsSearchDao(AnalyticsQueryClient analyticsQueryClient) {
        this.analyticsQueryClient = analyticsQueryClient;
    }

    public List<Map<String, Object>> fetchFacetsThatHaveExpression(SemanticQuery geneQuery, SemanticQuery conditionQuery, String species) {
        String response =
                analyticsQueryClient.queryBuilder()
                .baselineFacets()
                .queryIdentifierSearch(geneQuery)
                .queryConditionsSearch(conditionQuery)
                .ofSpecies(species)
                .fetch();
        return JsonPath.read(response, FACET_TREE_PATH);
    }

    public List<Map<String, Object>> fetchFacetsThatHaveExpression(SemanticQuery query) {

        String response =
                analyticsQueryClient.queryBuilder()
                        .baselineFacets()
                        .queryIdentifierOrConditionsSearch(query)
                        .fetch();
        return JsonPath.read(response, FACET_TREE_PATH);
    }

    public List<Map<String, Object>> fetchExpressionLevelFaceted(SemanticQuery geneQuery, SemanticQuery conditionQuery, String species, String defaultQueryFactorType) {
        String response = analyticsQueryClient.queryBuilder()
                .baselineFacets()
                .queryIdentifierSearch(geneQuery)
                .queryConditionsSearch(conditionQuery)
                .ofSpecies(species)
                .withFactorType(defaultQueryFactorType)
                .fetch();

        return JsonPath.read(response,EXPERIMENTS_PATH);
    }

    public List<Map<String, Object>> fetchExpressionLevelFaceted(SemanticQuery query, String species, String defaultQueryFactorType) {
        String response = analyticsQueryClient.queryBuilder()
                .baselineFacets()
                .queryIdentifierOrConditionsSearch(query)
                .ofSpecies(species)
                .withFactorType(defaultQueryFactorType).fetch();

        return JsonPath.read(response,EXPERIMENTS_PATH);
    }

}

@@ -1466,383 +1466,8 @@
  %7D%0A%0A
-    public List%3CMap%3CString, Object%3E%3E fetchFacetsThatHaveExpression(SemanticQuery query) %7B%0A%0A        String response =%0A                analyticsQueryClient.queryBuilder()%0A                        .baselineFacets()%0A                        .queryIdentifierOrConditionsSearch(query)%0A                        .fetch();%0A        return JsonPath.read(response, FACET_TREE_PATH);%0A    %7D%0A%0A
     
@@ -2019,461 +2019,6 @@
  %7D%0A%0A
-    public List%3CMap%3CString, Object%3E%3E fetchExpressionLevelFaceted(SemanticQuery query, String species, String defaultQueryFactorType) %7B%0A        String response = analyticsQueryClient.queryBuilder()%0A                .baselineFacets()%0A                .queryIdentifierOrConditionsSearch(query)%0A                .ofSpecies(species)%0A                .withFactorType(defaultQueryFactorType).fetch();%0A%0A        return JsonPath.read(response,EXPERIMENTS_PATH);%0A    %7D%0A%0A
 %7D%0A

Remove dead code