package initialize

import (
	"kra/internal/plugin/announcement/router"
	"kra/internal/server/middleware"

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

// RouterConfig 路由配置
type RouterConfig struct {
	RouterPrefix string
}

func Router(engine *gin.Engine, db *gorm.DB) {
	RouterWithConfig(engine, db, nil)
}

func RouterWithConfig(engine *gin.Engine, db *gorm.DB, cfg *RouterConfig) {
	// 获取配置中的路由前缀
	routerPrefix := ""
	if cfg != nil {
		routerPrefix = cfg.RouterPrefix
	}

	public := engine.Group(routerPrefix)
	private := engine.Group(routerPrefix)
	private.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())

	routerInstance := router.NewRouter(db)
	routerInstance.Info.Init(public, private)
}
