// Copyright (C) 2019 Marius Schellenberger

package server

import "git.giftfish.de/ston1th/docstore/pkg/core"

type route struct {
	Path    string
	Handler ctxHandler
	Methods []string
}

var static = []route{
	{
		core.Favicon,
		staticHandler,
		[]string{"GET"},
	},
	{
		core.BootstrapCSS,
		staticHandler,
		[]string{"GET"},
	},
	{
		core.CustomCSS,
		staticHandler,
		[]string{"GET"},
	},
}

var registerRoutes = append(static, route{
	core.IndexURI,
	jwtRegisterHandler(
		registerHandler),
	[]string{"GET", "POST"},
})

var prefixRoutes = []route{
	{
		core.RawPrefix,
		jwtHandler(
			authHandler(
				rawHandler)),
		[]string{"GET"},
	},
	{
		core.IndexPrefix,
		jwtHandler(
			authHandler(
				indexHandler)),
		[]string{"GET", "POST"},
	},
	{
		core.UploadPrefix,
		jwtHandler(
			authHandler(
				uploadHandler)),
		[]string{"GET", "POST"},
	},
	{
		core.NewPrefix,
		jwtHandler(
			authHandler(
				newDirHandler)),
		[]string{"GET", "POST"},
	},
	{
		core.MovePrefix,
		jwtHandler(
			authHandler(
				moveHandler)),
		[]string{"GET", "POST"},
	},
	{
		core.DeletePrefix,
		jwtHandler(
			authHandler(
				deleteHandler)),
		[]string{"GET", "POST"},
	},
	{
		core.IndexURI,
		jwtHandler(
			authHandler(
				dirHandler)),
		[]string{"GET"},
	},
}

var routes = append(static, []route{
	{
		"/search",
		jwtHandler(
			authHandler(
				searchHandler)),
		[]string{"GET", "POST"},
	},
	{
		core.LoginURI,
		jwtHandler(
			loginHandler),
		[]string{"GET", "POST"},
	},
	{
		core.TotpURI,
		jwtHandler(
			totpAuthHandler(
				loginTotpHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/user/edit",
		jwtHandler(
			authHandler(
				userEditHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/user/totp",
		jwtHandler(
			authHandler(
				userTotpHandler)),
		[]string{"GET", "POST"},
	},
	{
		core.LogoutURI,
		jwtHandler(
			logoutHandler),
		[]string{"GET", "POST"},
	},
}...)
