// Package control exposes the private, capability-authenticated daemon control
// plane. It is intentionally registered outside the business API auth group.
package control

import (
	"github.com/gin-gonic/gin"

	"github.com/tidbcloud/AgentTeam/desktop/internal/daemoncontrol"
)

const (
	RootPath           = "/api/internal/control/v2"
	ControlTokenHeader = "X-AgentTeam-Control-Token"
)

type Dependencies struct {
	Controller      *daemoncontrol.Controller
	RequestShutdown func()
	UISessions      UISessionControl
}

func RegisterRoutes(router *gin.Engine, dependencies Dependencies) {
	if router == nil || dependencies.Controller == nil {
		return
	}
	handlers := newHandlers(dependencies)
	group := router.Group(RootPath)
	group.GET("/identity", handlers.identity)
	group.POST("/ui-sessions", handlers.createUISession)
	group.POST("/ui-sessions/renew", handlers.renewUISession)
	group.POST("/ui-sessions/ensure", handlers.ensureUISession)
	group.POST("/ui-sessions/revoke", handlers.revokeUISession)
	group.POST("/adopt", handlers.adopt)
	group.POST("/shutdown", handlers.shutdown)
}
