package api

import (
	"github.com/gogf/gf/v2/net/ghttp"
	"go.uber.org/dig"
	"yx-dataset-server/library/auth"
	"yx-dataset-server/library/middleware"
	"yx-dataset-server/router/api/controllers"
)

// 注册路由
func RegisterRouters(s *ghttp.Server, container *dig.Container) error {
	controllers.Inject(container)
	gr := s.Group("/api")
	// 注册请求限制中间件
	return container.Invoke(func(
		auth auth.Auther,
		cLogin *controllers.Login,
	//cOrganization *controllers.Organization,
	//
	//cUser *controllers.User,
	//cDataset *controllers.Datasets,
	//cDatasetFile *controllers.DatasetFile,
	//
	//cMenu *controllers.Menu,
	//cRole *controllers.Role,
	//
	//cLogin *controllers.Login,
	//cFile *controllers.File,

		cChatAssistant *controllers.ChatAssistant,
		cChatMessage *controllers.ChatMessage,
		cChatSession *controllers.ChatSession,

	) {
		gr.Middleware(middleware.UserAuthMiddleware(auth,
			middleware.AllowMethodAndPathPrefixSkipper(
				middleware.JoinRouter("GET", "/api/v1/login"),
				middleware.JoinRouter("POST", "/api/v1/login"),
				//middleware.JoinRouter("POST", "/api/v1/chat_messages/v1"),
			),
		))
		v1 := gr.Group("/v1")
		{
			// 登录
			gLogin := v1.Group("/login")
			{
				gLogin.POST("/", cLogin.Login)
				gLogin.POST("/exit", cLogin.Logout)
				gLogin.PUT("/refresh/token", cLogin.RefreshToken)
			}

			v1.GET("/current/user", cLogin.GetUserInfo)

			gChatAssistant := v1.Group("/chat_assistants")
			{
				gChatAssistant.GET("/", cChatAssistant.Query)
				gChatAssistant.GET("/:id", cChatAssistant.Get)
				gChatAssistant.POST("/", cChatAssistant.Create)
				gChatAssistant.PUT("/:id", cChatAssistant.Update)
				gChatAssistant.DELETE("/:id", cChatAssistant.Delete)
			}
			gChatSession := v1.Group("/chat_sessions")
			{
				gChatSession.GET("/", cChatSession.Query)
				gChatSession.GET("/:id", cChatSession.Get)
				gChatSession.POST("/", cChatSession.Create)
				gChatSession.PUT("/:id", cChatSession.Update)
				gChatSession.DELETE("/:id", cChatSession.Delete)
			}
			gChatMessage := v1.Group("/chat_messages")
			{
				gChatMessage.GET("/", cChatMessage.Query)
				gChatMessage.GET("/:id", cChatMessage.Get)
				gChatMessage.POST("/", cChatMessage.ChatMessage)
				gChatMessage.POST("/stream", cChatMessage.StreamChatMessage)
				gChatMessage.PUT("/:id", cChatMessage.Update)
				gChatMessage.DELETE("/:id", cChatMessage.Delete)
			}
		}
	})
}
