package router

import (
	"dsbqj-admin/app/api/hotupdate"
	v1 "dsbqj-admin/app/api/v1"
	"dsbqj-admin/middleware"
	"os"

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

// NewRouter 路由配置
func NewRouter() *gin.Engine {
	r := gin.New()

	// 中间件, 顺序不能改
	r.Use(middleware.Session(os.Getenv("SESSION_SECRET")))
	r.Use(middleware.Cors())
	r.Use(gin.Recovery())

	// 路由
	apiv1 := r.Group("/api/v1")
	{
		//apiv1.POST("upload/data", v1.UploadReport)

		apiv1.POST("version/check", v1.CheckVersion)
		apiv1.POST("version/server", v1.ServerVersion)
	}

	webv1 := r.Group("/web/v1")
	{
		webv1.GET("versions", v1.ShowVersions)
		webv1.POST("version", v1.VersionCreate)
		webv1.PUT("version", v1.VersionEdit)
		webv1.DELETE("version/:key", v1.VersionDelete)
		webv1.POST("version/reload", v1.ReloadVersion)
	}

	pointv1 := r.Group("/point/v1")
	{
		pointv1.POST("thinkingdata", v1.ThinkingData)
	}

	subscribev1 := r.Group("/subscribe/v1")
	{
		subscribev1.POST("/open", v1.Open)   // 标记开启订阅
		subscribev1.POST("/close", v1.Close) // 标记关闭订阅
		subscribev1.POST("/check", v1.Check) // 检查用户当前订阅
		subscribev1.POST("/send", v1.Send)   // 触发订阅直接发送
		subscribev1.POST("/task", v1.Task)   // 触发订阅任务发送
	}

	hotupdateR := r.Group("/hotupdate")
	{
		hotupdateR.GET("/getversion", hotupdate.GetVersion)
		hotupdateR.GET("/addversion", hotupdate.AddVersion)
	}
	//webv1.Use(middleware.BodyHandler())
	//{
	//
	//	// 需要登录保护的
	//	authed := webv1.Group("/")
	//authed.Use(middleware.AdminRequired())
	//	{
	//
	//	}
	//

	return r
}
