package activitytemplate

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

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

func RegisterRoutes(protected *gin.RouterGroup, h *Handler) {
	if h == nil {
		return
	}
	protected.GET("/admin/activities/templates", middleware.RequirePermission("activity-template:view"), h.List)
	protected.POST("/admin/activities/templates", middleware.RequirePermission("activity-template:create"), h.Create)
	protected.POST("/admin/activities/templates/validate", middleware.RequireAnyPermission("activity-template:create", "activity-template:update", "activity-template:publish"), h.Validate)
	protected.GET("/admin/activities/templates/:template_id", middleware.RequirePermission("activity-template:view"), h.Get)
	protected.PUT("/admin/activities/templates/:template_id", middleware.RequirePermission("activity-template:update"), h.Update)
	protected.PATCH("/admin/activities/templates/:template_id/status", middleware.RequirePermission("activity-template:publish"), h.SetStatus)
	protected.DELETE("/admin/activities/templates/:template_id", middleware.RequirePermission("activity-template:delete"), h.Delete)
	protected.GET("/admin/activities/templates/:template_id/versions", middleware.RequirePermission("activity-template:view"), h.Versions)
	protected.POST("/admin/activities/templates/:template_id/clone", middleware.RequirePermission("activity-template:create"), h.Clone)
	protected.GET("/admin/activities/templates/:template_id/leaderboard", middleware.RequirePermission("activity-template:data"), h.Leaderboard)
	protected.GET("/admin/activities/templates/:template_id/data", middleware.RequirePermission("activity-template:data"), h.Data)
	// 导出复用同一受限聚合契约，前端按 overview/trend/gifts/tasks 分区生成 CSV；避免另开一条可能绕过 366 天和 Top100 限制的数据链路。
	protected.GET("/admin/activities/templates/:template_id/data/export", middleware.RequirePermission("activity-template:export"), h.Data)
	protected.GET("/admin/activities/templates/:template_id/rewards", middleware.RequirePermission("activity-template:data"), h.RewardJobs)
	protected.POST("/admin/activities/templates/:template_id/rewards/:reward_job_id/retry", middleware.RequirePermission("activity-template:retry"), h.RetryRewardJob)
	protected.GET("/admin/activities/templates/:template_id/task-claims", middleware.RequirePermission("activity-template:data"), h.TaskClaims)
	protected.POST("/admin/activities/templates/:template_id/task-claims/:claim_id/retry", middleware.RequirePermission("activity-template:retry"), h.RetryTaskClaim)
}
