package robot

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/robot/controllers"
)

// 注册路由
func RegisterRouters(s *ghttp.Server, container *dig.Container) error {
	controllers.Inject(container)
	gr := s.Group("/robot")
	// 注册请求限制中间件
	return container.Invoke(func(
		auth auth.Auther,

		cRobot *controllers.Robot,

	) {
		gr.Middleware(middleware.UserAuthMiddleware(auth,
			middleware.AllowMethodAndPathPrefixSkipper(
				middleware.JoinRouter("POST", "/robot/v1/robots/receive"),
				middleware.JoinRouter("POST", "/robot/v1/robots/stream"),
			),
		))
		v1 := gr.Group("/v1")
		{
			gRobot := v1.Group("/robots")
			{
				// HTTP Webhook模式（文本回复）
				gRobot.POST("/receive/:id", cRobot.ReceiveMessage)
			}
		}
	})
}
