package collaboration

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/dig"

	"github.com/tidbcloud/aisupport/packages/sdk-go/infra/apiserver"
	"github.com/tidbcloud/aisupport/services/ticket-manager/internal/app"
	collabsvcapi "github.com/tidbcloud/aisupport/services/ticket-manager/internal/services/collaboration/api"
)

type HandlerParam struct {
	dig.In

	Collaboration collabsvcapi.Service
}

type Handler struct {
	Collaboration collabsvcapi.Service
}

func NewHandler(param HandlerParam) app.HandlerResult {
	return app.HandlerResult{
		Handler: &Handler{
			Collaboration: param.Collaboration,
		},
	}
}

func (h *Handler) Name() string {
	return "CollaborationHandler"
}

func (h *Handler) Register(routers map[apiserver.RoutePath]gin.IRouter) error {
	router := routers[app.APIRoutePath]

	g := router.Group("/collaboration")

	bg := g
	{
		bg.GET("/resources", h.ListResources)
		bg.POST("/resources", h.CreateResource)
		bg.GET("/resources/:id", h.GetResource)
		bg.PUT("/resources/:id", h.UpdateResource)
		bg.DELETE("/resources/:id", h.DeleteResource)
	}

	return nil
}
