package router

import (
	"metazone.cc/metalab/internal/config"
	"metazone.cc/metalab/internal/middleware"

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

// Setup 注册所有路由
func Setup(r *gin.Engine, db *gorm.DB, cfg *config.Config, siteSettings *config.SiteSettings) {
	r.Use(middleware.SecurityHeaders())
	r.Use(middleware.InjectSiteInfo(siteSettings))

	deps := buildDeps(db, cfg, siteSettings)

	// 维护模式中间件（全局，在路由匹配之前）
	r.Use(deps.maintenanceMdw.Handler())

	setupFrontendRoutes(r, cfg, deps)
	setupAPIRoutes(r, cfg, deps)
	setupAdminRoutes(r, cfg, deps)
}
