package setup

import (
	"gitlab.thpeetz.de/kontor/kontor-go/pkg/admin"
	"gitlab.thpeetz.de/kontor/kontor-go/pkg/auth"
	"gitlab.thpeetz.de/kontor/kontor-go/pkg/comics"
	"gitlab.thpeetz.de/kontor/kontor-go/pkg/library"
	"gitlab.thpeetz.de/kontor/kontor-go/pkg/office"
	"gitlab.thpeetz.de/kontor/kontor-go/pkg/tradingcards"
	"gitlab.thpeetz.de/kontor/kontor-go/pkg/tysc"
	"gitlab.thpeetz.de/kontor/kontor-go/pkg/util"

	"github.com/gin-gonic/gin"
)

// InitializeRoutes setup the routes for Kontor web application.
func InitializeRoutes(router *gin.Engine) {

	// Use the setUserStatus middleware for every route to set a flag
	// indicating whether the request was from an authenticated user or not
	router.Use(auth.SetSessionStatus())

	// Handle the index route
	router.GET("/", util.ShowIndexPage)

	userRoutes := router.Group("/user")
	{
		userRoutes.GET("/login", auth.EnsureNotLoggedIn(), admin.ShowLoginPage)
		userRoutes.POST("/login", auth.EnsureNotLoggedIn(), admin.PerformLogin)
		userRoutes.GET("/logout", auth.EnsureLoggedIn(), admin.Logout)
	}
	admin.GetRoutes(router)
	comics.GetRoutes(router)
	library.GetRoutes(router)
	office.GetRoutes(router)
	tradingcards.GetRoutes(router)
	tysc.GetRoutes(router)
}
