package uibuilder

import (
	"net/http"

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

func (a *UIBuilder) routes() []plugins.Route {
	middleware := (&chain{}).Wrap
	return []plugins.Route{
		{
			Name:        "Save search preference",
			Methods:     []string{http.MethodPut},
			Path:        "/_uibuilder/{id}/search",
			HandlerFunc: middleware(a.putSearchPreference(), false),
			Description: "To save search preference",
		},
		{
			Name:        "Save recommendation preference",
			Methods:     []string{http.MethodPut},
			Path:        "/_uibuilder/{id}/recommendation",
			HandlerFunc: middleware(a.putRecommendationPreference(), false),
			Description: "To save recommendation preference",
		},
		{
			Name:        "Get search preference",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/search",
			HandlerFunc: middleware(a.getSearchPreference(), false),
			Description: "To get search preference",
		},
		{
			Name:        "Get recommendation preference",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/recommendation",
			HandlerFunc: middleware(a.getRecommendationPreference(), false),
			Description: "To get recommendation preference",
		},
		{
			Name:        "Delete search preference",
			Methods:     []string{http.MethodDelete},
			Path:        "/_uibuilder/{id}/search",
			HandlerFunc: middleware(a.deletePreference(), false),
			Description: "To delete search preference",
		},
		{
			Name:        "Delete recommendation preference",
			Methods:     []string{http.MethodDelete},
			Path:        "/_uibuilder/{id}/recommendation",
			HandlerFunc: middleware(a.deletePreference(), false),
			Description: "To delete recommendation preference",
		},
		{
			Name:        "Get search preferences",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/search",
			HandlerFunc: middleware(a.getSearchPreferences(), false),
			Description: "To get a list of search preferences",
		},
		{
			Name:        "Get recommendation preferences",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/recommendation",
			HandlerFunc: middleware(a.getRecommendationPreferences(), false),
			Description: "To get a list of recommendation preferences",
		},
		{
			Name:        "To store the latest code",
			Methods:     []string{http.MethodPut},
			Path:        "/_uibuilder/{id}/code",
			HandlerFunc: middleware(a.putUIbuilderCode(), false),
			Description: "To store latest code version for ui builder",
		},
		{
			Name:        "To retrieve the latest code",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/code",
			HandlerFunc: middleware(a.getUIbuilderCode(), false),
			Description: "To get the latest code version for ui builder",
		},
		{
			Name:        "To retrieve the code by version",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/code/version/{versionId}",
			HandlerFunc: middleware(a.getUIbuilderCodeByVersion(), false),
			Description: "To get the code for a specific version",
		},
		{
			Name:        "To list all the active versions",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/code/versions",
			HandlerFunc: middleware(a.getUIbuilderCodeVersions(), false),
			Description: "To get the list of versions",
		},
		{
			Name:        "To deploy the code",
			Methods:     []string{http.MethodPut},
			Path:        "/_uibuilder/{id}/deploy",
			HandlerFunc: middleware(a.deployUIbuilderCode(), false),
			Description: "To deploy and host the code",
		},
		{
			Name:        "To retrieve the deployment",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/deploy",
			HandlerFunc: middleware(a.getUIbuilderLatestDeployment(), false),
			Description: "To get the latest deployment",
		},
		{
			Name:        "To retrieve deployment for a given ID",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/deploy/{deploymentID}",
			HandlerFunc: middleware(a.getUIbuilderDeploymentByID(), false),
			Description: "To get deployment details for deployment ID",
		},
		{
			Name:        "To cancel deployment for a given ID",
			Methods:     []string{http.MethodPatch},
			Path:        "/_uibuilder/{id}/deploy/{deploymentID}/cancel",
			HandlerFunc: middleware(a.cancelUIbuilderDeploymentByID(), false),
			Description: "To cancel an active deployment",
		},
		{
			Name:        "To delete deployment for a given ID",
			Methods:     []string{http.MethodDelete},
			Path:        "/_uibuilder/{id}/deploy/{deploymentID}",
			HandlerFunc: middleware(a.deleteUIbuilderDeploymentByID(), false),
			Description: "To delete deployment",
		},
		{
			Name:        "To add env variables",
			Methods:     []string{http.MethodPost},
			Path:        "/_uibuilder/{id}/env",
			HandlerFunc: middleware(a.createUIbuilderEnv(), false),
			Description: "To create envs",
		},
		{
			Name:        "To get envs",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/env",
			HandlerFunc: middleware(a.getUIbuilderEnvs(), false),
			Description: "To get envs",
		},
		{
			Name:        "To edit env variable",
			Methods:     []string{http.MethodPatch},
			Path:        "/_uibuilder/{id}/env/{envID}",
			HandlerFunc: middleware(a.editUIbuilderEnv(), false),
			Description: "To edit env variable by env name",
		},
		{
			Name:        "To delete env variable",
			Methods:     []string{http.MethodDelete},
			Path:        "/_uibuilder/{id}/env/{envID}",
			HandlerFunc: middleware(a.deleteUIbuilderEnv(), false),
			Description: "To create envs",
		},
		{
			Name:        "To verify a domain",
			Methods:     []string{http.MethodPost},
			Path:        "/_uibuilder/{id}/domain/{domainID}",
			HandlerFunc: middleware(a.verifyUIbuilderDomainByID(), true),
			Description: "To verify domain",
		},
		{
			Name:        "To create a domain",
			Methods:     []string{http.MethodPost},
			Path:        "/_uibuilder/{id}/domain",
			HandlerFunc: middleware(a.createUIbuilderDomain(), true),
			Description: "To create a domain",
		},
		{
			Name:        "To get registered domains",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/domain",
			HandlerFunc: middleware(a.getUIbuilderDomains(), true),
			Description: "To get registered domains",
		},
		{
			Name:        "To get domain config",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/{id}/domain/{domainID}",
			HandlerFunc: middleware(a.getUIbuilderDomainConfigByID(), true),
			Description: "To get domain config by domain ID",
		},
		{
			Name:        "To remove a domain",
			Methods:     []string{http.MethodDelete},
			Path:        "/_uibuilder/{id}/domain/{domainID}",
			HandlerFunc: middleware(a.deleteUIbuilderDomainByID(), true),
			Description: "To remove a domain to uibuilder",
		},
		{
			Name:        "Creates searchbox preference",
			Methods:     []string{http.MethodPut},
			Path:        "/_uibuilder/searchbox/{searchboxId}",
			HandlerFunc: middleware(a.saveSearchBox(), false),
			Description: "Create/Update searchbox preference by id",
		},
		{
			Name:        "Get searchbox preference",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/searchbox/{searchboxId}",
			HandlerFunc: middleware(a.getSearchBox(), false),
			Description: "Get searchbox preference by id",
		},
		{
			Name:        "Get searchbox preferences",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/searchboxes",
			HandlerFunc: middleware(a.getSearchBoxes(), false),
			Description: "Retrieves saved searchboxes preferences",
		},
		{
			Name:        "Delete searchbox preferences",
			Methods:     []string{http.MethodDelete},
			Path:        "/_uibuilder/searchbox/{searchboxId}",
			HandlerFunc: middleware(a.deleteSearchBox(), false),
			Description: "Deletes searchboxe preference by Id",
		},
		{
			Name:        "Create auth client",
			Methods:     []string{http.MethodPost},
			Path:        "/_uibuilder/authentication",
			HandlerFunc: middleware(a.createAuthClient(), true),
			Description: "Create an authentication client (aka Auth0 app)",
		},
		{
			Name:        "Get an auth client",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/authentication/{client_id}",
			HandlerFunc: middleware(a.getAuthClient(), true),
			Description: "Get an authentication client using its client_id",
		},
		{
			Name:        "Update an auth client",
			Methods:     []string{http.MethodPatch},
			Path:        "/_uibuilder/authentication/{client_id}",
			HandlerFunc: middleware(a.updateAuthClient(), true),
			Description: "Update an authentication client using its client_id",
		},
		{
			Name:        "Delete an auth client",
			Methods:     []string{http.MethodDelete},
			Path:        "/_uibuilder/authentication/{client_id}",
			HandlerFunc: middleware(a.deleteAuthClient(), true),
			Description: "Delete an authentication client using its client_id",
		},
		{
			Name:        "Create an auth user",
			Methods:     []string{http.MethodPost},
			Path:        "/_uibuilder/auth_user",
			HandlerFunc: middleware(a.createAuthUser(), true),
			Description: "Create an auth user, this represents an end-user",
		},
		{
			Name:        "Get a list of auth users by application client_id",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/auth_users",
			HandlerFunc: middleware(a.getAuthUsers(), true),
			Description: "Get a list of auth users by application client_id",
		},
		{
			Name:        "Get an auth user",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/auth_user/{user_id}",
			HandlerFunc: middleware(a.getAuthUser(), true),
			Description: "Get an auth user using its user_id",
		},
		{
			Name:        "Update an auth user",
			Methods:     []string{http.MethodPatch},
			Path:        "/_uibuilder/auth_user/{user_id}",
			HandlerFunc: middleware(a.updateAuthUser(), true),
			Description: "Update an auth user using its user_id",
		},
		{
			Name:        "Delete an auth user",
			Methods:     []string{http.MethodDelete},
			Path:        "/_uibuilder/auth_user/{user_id}",
			HandlerFunc: middleware(a.deleteAuthUser(), true),
			Description: "Delete an auth user using its user_id",
		},
		{
			Name:        "Set auth preferences",
			Methods:     []string{http.MethodPut},
			Path:        "/_uibuilder/auth_preferences",
			HandlerFunc: middleware(a.setAuthPreference(), true),
			Description: "Sets authentication preferences for UI Builder",
		},
		{
			Name:        "Get auth preferences",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/auth_preferences",
			HandlerFunc: middleware(a.getAuthPreference(), true),
			Description: "Gets authentication preferences for UI Builder",
		},
		{
			Name:        "Set auth preferences",
			Methods:     []string{http.MethodPut},
			Path:        "/_uibuilder/auth_preference",
			HandlerFunc: middleware(a.setAuthPreference(), true),
			Description: "Sets authentication preference for UI Builder (support for singular route)",
		},
		{
			Name:        "Get auth preferences",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/auth_preference",
			HandlerFunc: middleware(a.getAuthPreference(), true),
			Description: "Gets authentication preference for UI Builder (support for singular route)",
		},
		{
			Name:        "Create an auth connection",
			Methods:     []string{http.MethodPost},
			Path:        "/_uibuilder/auth_connection",
			HandlerFunc: middleware(a.createAuthConnection(), true),
			Description: "Create an authentication connection (for SAML only)",
		},
		{
			Name:        "Get an auth connection",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/auth_connection/{conn_id}",
			HandlerFunc: middleware(a.getAuthConnection(), true),
			Description: "Get an authentication connection by its connection_id",
		},
		{
			Name:        "Update an auth connection",
			Methods:     []string{http.MethodPatch},
			Path:        "/_uibuilder/auth_connection/{conn_id}",
			HandlerFunc: middleware(a.updateAuthConnection(), true),
			Description: "Update an authentication connection using its connection_id",
		},
		{
			Name:        "Delete an auth connection",
			Methods:     []string{http.MethodDelete},
			Path:        "/_uibuilder/auth_connection/{conn_id}",
			HandlerFunc: middleware(a.deleteAuthConnection(), true),
			Description: "Delete an authentication connection using its connection_id",
		},
		{
			Name:        "Get authentication connections for a client",
			Methods:     []string{http.MethodGet},
			Path:        "/_uibuilder/auth_connection_state/{client_id}",
			HandlerFunc: middleware(a.getAuthConnectionState(), true),
			Description: "Get an authentication connection by its client_id",
		},
		{
			Name:        "Update authentication connections for a client",
			Methods:     []string{http.MethodPut},
			Path:        "/_uibuilder/auth_connection_state/{client_id}",
			HandlerFunc: middleware(a.updateAuthConnectionState(), true),
			Description: "Update an authentication connection using its client_id",
		},
	}
}
