package cmd

import (
	"context"
	"server/internal/controller/activity"
	"server/internal/controller/admin"
	"server/internal/controller/auth"
	"server/internal/controller/author"
	"server/internal/controller/book"
	"server/internal/controller/category"
	"server/internal/controller/chapter"
	"server/internal/controller/feedback"
	"server/internal/controller/recommend"
	"server/internal/controller/system"
	"server/internal/controller/task"
	"server/internal/controller/user"
	"server/internal/middleware"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/", func(group *ghttp.RouterGroup) {
				group.Middleware(middleware.Language) // 语言检测中间件
				group.Middleware(middleware.Response)
				group.Middleware(ghttp.MiddlewareCORS)
				group.Bind(
					auth.NewV1(),
				)
				group.Group("/", func(group *ghttp.RouterGroup) {
					group.Middleware(middleware.Auth)
					group.Middleware(middleware.Casbin)
					group.Bind(
						admin.NewV1(),
						author.NewV1(),
						book.NewV1(),
						category.NewV1(),
						chapter.NewV1(),
						feedback.NewV1(),
						user.NewV1(),
						recommend.NewV1(),
						activity.NewV1(),
						task.NewV1(),
						system.NewV1(),
					)
				})
			})
			s.Run()
			return nil
		},
	}
)
