package router

import (
	"github.com/gin-gonic/gin"
	file "iot_manager_service/app/file/controller"
	"iot_manager_service/app/middleware"
	user "iot_manager_service/app/user/controller"
	"iot_manager_service/config"
	"iot_manager_service/util/logger"
	"iot_manager_service/util/websocket"
)

func InitRouter(engine *gin.Engine) {
	// 跨域处理
	engine.Use(middleware.Cors())
	// 校验token令牌
	engine.Use(middleware.AuthMiddleware())

	engine.Use(gin.Recovery())
	if config.Instance().Logger.Switch == 1 {
		engine.Use(logger.LogToFile())
	}
	engine.Use(logger.Recover)

	//用户
	sys := engine.Group("/user")
	{
		sys.GET("/getPublicKey", user.SysUserController.GetPublicKey)
		sys.POST("/login", user.SysUserController.Login)
		sys.POST("/logout", user.SysUserController.Logout)
		sys.POST("/getDeptUsers", user.SysUserController.GetDeptSysUsers)
		sys.GET("/getNewTokens", user.SysUserController.GetNewTokens)
		sys.GET("/getUserInfo", user.SysUserController.GetSysUserInfo)
		sys.GET("/getDepts", user.SysUserController.GetDepts)
	}

	//文件
	files := engine.Group("/file")
	{
		files.POST("/distribute", file.FileController.Distribute)
		files.GET("/getMyUpload", file.FileController.GetMyUploadFiles)
		files.POST("/getUserFiles", file.FileController.GetSysUserFiles)
		files.POST("/upload", file.FileController.Upload)
		files.GET("/viewFile", file.FileController.ViewFile)
		files.GET("/downloadFile", file.FileController.DownloadFile)
		files.POST("/forwardingFile", file.FileController.ForwardingFile)

	}

	//下发通知
	notice := engine.Group("/notice")
	{
		//请求Websocket连接
		notice.GET("/websocket", websocket.HandleWebSocket)
	}

	//demo := engine.Group("/demo")
	//{
	//	//请求Websocket连接
	//	//demo.POST("/shangChuan", file.FileController.ShangChuan)
	//}

}
