package analytics

import (
	"net/http"

	"github.com/appbaseio-confidential/reactivesearch/plugins"
)

func (a *Analytics) routes() []plugins.Route {
	middleware := (&chain{}).Wrap
	return []plugins.Route{
		{
			Name:        "Get Analytics Preferences",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/preferences",
			HandlerFunc: middleware(a.getPreferences()),
			Description: "Return the preferences for analytics",
		},
		{
			Name:        "Set Analytics Preferences",
			Methods:     []string{http.MethodPost},
			Path:        "/_analytics/preferences",
			HandlerFunc: middleware(a.setPreferences()),
			Description: "Set the passed preferences as analytics preferences",
		},
		{
			Name:        "Get overview",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/overview",
			HandlerFunc: middleware(a.getOverview()),
			Description: "Returns analytics overview of an index or set of indices",
		},
		{
			Name:        "Get overview",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/overview",
			HandlerFunc: middleware(a.getOverview()),
			Description: "Returns analytics overview of a cluster",
		},
		{
			Name:        "Get advanced",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/advanced",
			HandlerFunc: middleware(a.getAdvanced()),
			Description: "Returns advanced analytics of an index or set of indices",
		},
		{
			Name:        "Get advanced",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/advanced",
			HandlerFunc: middleware(a.getAdvanced()),
			Description: "Returns advanced analytics of a cluster",
		},
		{
			Name:        "Get popular searches",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/popular-searches",
			HandlerFunc: middleware(a.getPopularSearches()),
			Description: "Returns popular searches on an or set of indices",
		},
		{
			Name:        "Get popular searches",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/popular-searches",
			HandlerFunc: middleware(a.getPopularSearches()),
			Description: "Returns popular searches on a cluster",
		},
		{
			Name:        "Get recent searches",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/recent-searches",
			HandlerFunc: middleware(a.getRecentSearches()),
			Description: "Returns recent searches on an or set of indices",
		},
		{
			Name:        "Get recent searches",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/recent-searches",
			HandlerFunc: middleware(a.getRecentSearches()),
			Description: "Returns recent searches on a cluster",
		},
		{
			Name:        "Get no result searches",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/no-result-searches",
			HandlerFunc: middleware(a.getNoResultSearches()),
			Description: "Returns no result searches on an index or set of indices",
		},
		{
			Name:        "Get no result searches",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/no-result-searches",
			HandlerFunc: middleware(a.getNoResultSearches()),
			Description: "Returns no result searches on a cluster",
		},
		{
			Name:        "Get popular filters",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/popular-filters",
			HandlerFunc: middleware(a.getPopularFilters()),
			Description: "Returns popular filters on an index or set of indices",
		},
		{
			Name:        "Get popular filters",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/popular-filters",
			HandlerFunc: middleware(a.getPopularFilters()),
			Description: "Returns popular filters on a cluster",
		},
		{
			Name:        "Get popular results",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/popular-results",
			HandlerFunc: middleware(a.getPopularResults()),
			Description: "Returns popular results on an index or set of indices",
		},
		{
			Name:        "Get popular results",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/popular-results",
			HandlerFunc: middleware(a.getPopularResults()),
			Description: "Returns popular results on a cluster",
		},
		{
			Name:        "Get recent results",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/recent-results",
			HandlerFunc: middleware(a.getRecentResults()),
			Description: "Returns recent results on an index or set of indices",
		},
		{
			Name:        "Get recent results",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/recent-results",
			HandlerFunc: middleware(a.getRecentResults()),
			Description: "Returns recent results on a cluster",
		},
		{
			Name:        "Get geo distribution",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/geo-distribution",
			HandlerFunc: middleware(a.getGeoRequestsDistribution()),
			Description: "Returns search counts based on request/ip location on an index or set of indices",
		},
		{
			Name:        "Get geo distribution",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/geo-distribution",
			HandlerFunc: middleware(a.getGeoRequestsDistribution()),
			Description: "Returns search counts based on request/ip location on a cluster",
		},
		{
			Name:        "Get search latencies",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/latency",
			HandlerFunc: middleware(a.getSearchLatencies()),
			Description: "Returns search latencies for requests made on an index or set of indices",
		},
		{
			Name:        "Get search latencies",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/latency",
			HandlerFunc: middleware(a.getSearchLatencies()),
			Description: "Returns search latencies for requests made on a cluster",
		},
		{
			Name:        "Get summary",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/summary",
			HandlerFunc: middleware(a.getSummary()),
			Description: "Returns total searches, avg click and conversion rates on an index or set of indices",
		},
		{
			Name:        "Get summary",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/summary",
			HandlerFunc: middleware(a.getSummary()),
			Description: "Returns total searches, avg click and conversion rates on a cluster",
		},
		{
			Name:        "Get request distribution",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/request-distribution",
			HandlerFunc: middleware(a.getRequestDistribution()),
			Description: "Returns the request distribution of an index or set of indices over a given period of time",
		},
		{
			Name:        "Get request distribution",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/request-distribution",
			HandlerFunc: middleware(a.getRequestDistribution()),
			Description: "Returns the request distribution of a cluster over a given period of time",
		},
		{
			Name:        "Get analytics insights for an index",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/insights",
			HandlerFunc: middleware(a.getInsights()),
			Description: "Returns the insights of an index or set of indices over a given period of time",
		},
		{
			Name:        "Get analytics insights for cluster",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/insights",
			HandlerFunc: middleware(a.getInsights()),
			Description: "Returns the insights of a cluster over a given period of time",
		},
		{
			Name:        "Update the insight status for global insights",
			Methods:     []string{http.MethodPut},
			Path:        "/_analytics/insight-status",
			HandlerFunc: middleware(a.putInsightStatus()),
			Description: "Update the insight status for a particular insight at cluster level",
		},
		{
			Name:        "Update the insight status",
			Methods:     []string{http.MethodPut},
			Path:        "/_analytics/{index}/insight-status",
			HandlerFunc: middleware(a.putInsightStatus()),
			Description: "Update the insight status for a particular insight at index level",
		},
		{
			Name:        "Records search",
			Methods:     []string{http.MethodPut},
			Path:        "/{index}/_analytics/search",
			HandlerFunc: middleware(a.recordSearch()),
			Description: "Records the click analytics",
		},
		{
			Name:        "Records click",
			Methods:     []string{http.MethodPut},
			Path:        "/{index}/_analytics/click",
			HandlerFunc: middleware(a.recordClick()),
			Description: "Records click for multiple objects",
		},
		{
			Name:        "Records conversion",
			Methods:     []string{http.MethodPut},
			Path:        "/{index}/_analytics/conversion",
			HandlerFunc: middleware(a.recordConversion()),
			Description: "Record conversion for multiple objects",
		},
		{
			Name:        "Get filter labels",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/filter-labels",
			HandlerFunc: middleware(a.getFilterLabels()),
			Description: "Returns a list of filter labels.",
		},
		{
			Name:        "Get filter values",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/filter-values/{label}",
			HandlerFunc: middleware(a.getFilterValues()),
			Description: "Returns a list of up to top 10 values for the provided label for an index.",
		},
		{
			Name:        "Get filter values",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/filter-values/{label}",
			HandlerFunc: middleware(a.getFilterValues()),
			Description: "Returns a list of up to top 10 values for the provided label for a cluster.",
		},
		{
			Name:        "Get Query overview",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/{index}/query-overview",
			HandlerFunc: middleware(a.getQueryOverview()),
			Description: "Returns query overview of an index or set of indices",
		},
		{
			Name:        "Get Query overview",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/query-overview",
			HandlerFunc: middleware(a.getQueryOverview()),
			Description: "Returns query overview of a cluster",
		},
		{
			Name:        "Get stored queries usage",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/storedqueries/usage",
			HandlerFunc: middleware(a.getStoredQueriesUsage()),
			Description: "Returns stored queries usage for a cluster",
		},
		{
			Name:        "Get query rules usage",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/rules/usage",
			HandlerFunc: middleware(a.getRulesUsage()),
			Description: "Returns query rules usage for a cluster",
		},
		{
			Name:        "Create saved search",
			Methods:     []string{http.MethodPut},
			Path:        "/_analytics/save-search",
			HandlerFunc: middleware(a.putSavedSearch()),
			Description: "Creates a saved search",
		},
		{
			Name:        "Get saved searches",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/saved-searches",
			HandlerFunc: middleware(a.getSavedSearches()),
			Description: "Returns saved searches",
		},
		{
			Name:        "Create favorites",
			Methods:     []string{http.MethodPut},
			Path:        "/_analytics/favorite",
			HandlerFunc: middleware(a.putFavorite()),
			Description: "Creates a favorite",
		},
		{
			Name:        "Get favorites",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/favorites",
			HandlerFunc: middleware(a.getFavorites()),
			Description: "Returns favorites",
		},
		{
			Name:        "Save Recent Document for User",
			Methods:     []string{http.MethodPut},
			Path:        "/{index}/_analytics/document",
			HandlerFunc: middleware(a.saveRecentDocument()),
			Description: "Save the passed recent document against the user",
		},
		{
			Name:        "Get Recent Documents with Filters",
			Methods:     []string{http.MethodGet},
			Path:        "/_analytics/recent-documents",
			HandlerFunc: middleware(a.getRecentDocuments()),
			Description: "Filter the recent documents with various query params",
		},
	}
}
