package opscenter

import (
	"hyapp-admin-server/internal/middleware"

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

func RegisterRoutes(protected *gin.RouterGroup, h *Handler) {
	if h == nil {
		return
	}

	group := protected.Group("/admin/ops-center")
	group.GET("/apps", h.ListApps)
	if h.luckyGift == nil {
		return
	}

	// ops-center 是 admin-server 的衍生平台，沿用 admin 登录、审计和 lucky-gift 权限；
	// 路由层只换平台路径，不复制幸运礼物业务逻辑，避免形成第二套管理 API。
	group.GET("/lucky-gifts/config", middleware.RequirePermission("lucky-gift:view"), h.luckyGift.GetLuckyGiftConfig)
	group.PUT("/lucky-gifts/config", middleware.RequirePermission("lucky-gift:update"), h.luckyGift.UpsertLuckyGiftConfig)
	group.GET("/lucky-gifts/configs", middleware.RequirePermission("lucky-gift:view"), h.luckyGift.ListLuckyGiftConfigs)
	group.GET("/lucky-gifts/config/versions", middleware.RequirePermission("lucky-gift:view"), h.luckyGift.ListLuckyGiftConfigVersions)
	group.POST("/lucky-gifts/config/rollback", middleware.RequirePermission("lucky-gift:update"), h.luckyGift.RollbackLuckyGiftConfig)
	group.GET("/lucky-gifts/draws", middleware.RequirePermission("lucky-gift:view"), h.luckyGift.ListLuckyGiftDraws)
	group.GET("/lucky-gifts/summary", middleware.RequirePermission("lucky-gift:view"), h.luckyGift.GetLuckyGiftDrawSummary)
	group.GET("/lucky-gifts/user-profiles", middleware.RequirePermission("lucky-gift:view"), h.luckyGift.ListLuckyGiftUserProfiles)
	group.GET("/lucky-gifts/user-profile", middleware.RequirePermission("lucky-gift:view"), h.luckyGift.GetLuckyGiftUserProfile)
	group.GET("/lucky-gifts/pools", middleware.RequirePermission("lucky-gift:view"), h.luckyGift.ListLuckyGiftPoolBalances)
	group.POST("/lucky-gifts/pools/credit", middleware.RequirePermission("lucky-gift:pool-credit"), h.luckyGift.CreditLuckyGiftPoolBalance)
	group.POST("/lucky-gifts/pools/debit", middleware.RequirePermission("lucky-gift:pool-debit"), h.luckyGift.DebitLuckyGiftPoolBalance)
	group.GET("/lucky-gifts/experiments", middleware.RequirePermission("lucky-gift:view"), h.luckyGift.ListLuckyGiftExperiments)
	group.POST("/lucky-gifts/experiments", middleware.RequirePermission("lucky-gift:experiment"), h.luckyGift.CreateLuckyGiftExperiment)
	group.PATCH("/lucky-gifts/experiments/:experimentId", middleware.RequirePermission("lucky-gift:experiment"), h.luckyGift.UpdateLuckyGiftExperiment)
	group.PUT("/lucky-gifts/experiments/:experimentId/overrides", middleware.RequirePermission("lucky-gift:experiment"), h.luckyGift.SetLuckyGiftExperimentOverrides)
	group.POST("/lucky-gifts/experiments/:experimentId/end", middleware.RequirePermission("lucky-gift:experiment"), h.luckyGift.EndLuckyGiftExperiment)
}
