// Package router 主路由汇总入口
// 不含任何具体路由定义，仅调用各模块的 RegisterRoutes 函数
// 新增模块时在 Setup 函数中添加一行调用即可
package router

import (
	"time"

	"github.com/echochat/backend/app/admin"
	"github.com/echochat/backend/app/auth"
	"github.com/echochat/backend/app/contact"
	fileApp "github.com/echochat/backend/app/file"
	groupApp "github.com/echochat/backend/app/group"
	imApp "github.com/echochat/backend/app/im"
	meetingApp "github.com/echochat/backend/app/meeting"
	notifyApp "github.com/echochat/backend/app/notify"
	"github.com/echochat/backend/app/provider"
	transcribeApp "github.com/echochat/backend/app/transcribe"
	wsApp "github.com/echochat/backend/app/ws"
	"github.com/echochat/backend/pkg/middleware"
	"github.com/echochat/backend/pkg/utils"
	"github.com/gin-gonic/gin"
)

// Setup 注册所有路由
// 包含健康检查和各业务模块的路由注册
func Setup(engine *gin.Engine, app *provider.App) {
	// 健康检查（不经过业务中间件）
	engine.GET("/health", func(c *gin.Context) {
		utils.ResponseOK(c, gin.H{
			"status":  "ok",
			"service": "echochat",
			"time":    time.Now().Format("2006-01-02 15:04:05"),
		})
	})

	// JWT 认证中间件实例（有状态 JWT，通过 AuthService 校验 Redis）
	jwtAuth := middleware.JWTAuth(&app.Config.JWT, app.AuthService)

	// --- 各模块路由注册 ---
	auth.RegisterRoutes(engine, app.AuthController, app.AdminAuthController, jwtAuth)
	admin.RegisterRoutes(engine, app.UserManageController, app.OnlineController, app.ContactManageController, app.GroupManageController, app.MessageManageController, app.MeetingManageController, jwtAuth)
	wsApp.RegisterRoutes(engine, app.WSHandler)
	contact.RegisterRoutes(engine, app.ContactController, jwtAuth)
	imApp.RegisterRoutes(engine, app.IMController, jwtAuth)
	fileApp.RegisterRoutes(engine, app.FileController, jwtAuth)
	groupApp.RegisterRoutes(engine, app.GroupController, jwtAuth)
	notifyApp.RegisterRoutes(engine, app.NotifyController, jwtAuth)
	meetingApp.RegisterRoutes(engine, app.MeetingController, app.MeetingRecordingController, jwtAuth)
	transcribeApp.RegisterRoutes(engine, app.TranscribeController, jwtAuth)
}
