// Copyright (C) 2019 Marius Schellenberger

package server

import "git.giftfish.de/ston1th/gowiki/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 routes = []route{
	{
		"/",
		jwtHandler(
			indexHandler),
		[]string{"GET"},
	},
	{
		"/sections",
		jwtHandler(
			sectionsHandler),
		[]string{"GET"},
	},
	{
		"/section/new",
		jwtHandler(
			adminAuthHandler(
				sectionNewHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/section/edit/{section:[a-zA-Z0-9]+$}",
		jwtHandler(
			adminAuthHandler(
				sectionEditHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/section/del/{section:[a-zA-Z0-9]+$}",
		jwtHandler(
			adminAuthHandler(
				sectionDelHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/search",
		jwtHandler(
			searchHandler),
		[]string{"GET", "POST"},
	},
	{
		"/new",
		jwtHandler(
			authHandler(
				pageNewHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/login",
		jwtHandler(
			loginHandler),
		[]string{"GET", "POST"},
	},
	{
		"/totp",
		jwtHandler(
			totpAuthHandler(
				loginTotpHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/blacklist",
		jwtHandler(
			authHandler(
				pageBlacklistHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/users",
		jwtHandler(
			adminAuthHandler(
				usersHandler)),
		[]string{"GET"},
	},
	{
		"/user/new",
		jwtHandler(
			adminAuthHandler(
				userNewHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/user/edit/{user:[a-zA-Z0-9]+$}",
		jwtHandler(
			userAuthHandler(
				userEditHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/user/del/{user:[a-zA-Z0-9]+$}",
		jwtHandler(
			userAuthHandler(
				userDelHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/user/totp/{user:[a-zA-Z0-9]+$}",
		jwtHandler(
			userAuthHandler(
				userTotpHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/user/unlock/{user:[a-zA-Z0-9]+$}",
		jwtHandler(
			adminAuthHandler(
				userUnlockHandler)),
		[]string{"POST"},
	},
	{
		"/logout",
		jwtHandler(
			logoutHandler),
		[]string{"GET", "POST"},
	},
	{
		"/view/{key}",
		jwtHandler(
			pageHandler),
		[]string{"GET"},
	},
	{
		"/view/{key}/md",
		jwtHandler(
			pageMDHandler(
				pageHandler)),
		[]string{"GET"},
	},
	{
		"/{section:[a-zA-Z0-9]+}",
		jwtHandler(
			sectionHandler),
		[]string{"GET"},
	},
	{
		"/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}",
		jwtHandler(
			pageHandler),
		[]string{"GET"},
	},
	{
		"/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}/md",
		jwtHandler(
			pageMDHandler(
				pageHandler)),
		[]string{"GET"},
	},
	{
		"/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}/share",
		jwtHandler(
			pageShareHandler),
		[]string{"GET", "POST"},
	},
	{
		"/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}/edit",
		jwtHandler(
			authHandler(
				pageEditHandler)),
		[]string{"GET", "POST"},
	},
	{
		"/{section:[a-zA-Z0-9]+}/{title:[a-zA-Z0-9+-]+}/del",
		jwtHandler(
			authHandler(
				pageDelHandler)),
		[]string{"GET", "POST"},
	},
}
