package routing

import (
	"sync"

	"git.markbailey.dev/cerbervs/ptpp/handlers/admin"
	"git.markbailey.dev/cerbervs/ptpp/handlers/shared"
	"git.markbailey.dev/cerbervs/ptpp/lib/middleware"
)

var (
	rtrinst     *Router
	rtrinstOnce sync.Once
)

func NewRouter() *Router {
	rtrinstOnce.Do(func() {
		rtrinst = &Router{
			Mux:       nil,
			BasePath:  "/",
			BaseRoute: Route{Controller: shared.HomePageController{}, Path: "", Name: "app.index"},
			Routes: []Route{
				{Controller: shared.SignUpHandler{}, Path: "sign-up", Name: "app.user.sign_up"},
				{Controller: shared.SignInHandler{}, Path: "sign-in", Name: "app.user.sign_in"},
				{Controller: shared.SignOutHandler{}, Path: "sign-out", Name: "app.user.sign_out"},
				{Controller: shared.PopulateHandler{}, Path: "populate", Name: "app.populate"},
			},
			SubRouters: []*Router{
				{
					Mux:      nil,
					BasePath: "/admin/",
                    BaseRoute: Route{Controller: admin.IndexHandler{}, Path: "", Name: "app.admin.index"},
					Routes: []Route{
						{Controller: admin.IndexHandler{}, Path: "butt", Name: "app.admin.butt"},
					},
					SubRouters: nil,
					Middleware: &[]middleware.Func{middleware.WithAuth},
				},
			},
			Middleware: &[]middleware.Func{middleware.DontPanic, middleware.WithLogger, middleware.WithUsername},
		}
	})

	return rtrinst
}
