package handlers

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"sproutclaw-web/internal/models"
	"sproutclaw-web/internal/rpc"
)

// RegisterExtensionUI registers the extension UI response route.
func RegisterExtensionUI(r *gin.RouterGroup, piClient *rpc.Client) {
	r.POST("/extension-ui-response", func(c *gin.Context) {
		var req models.ExtensionUIResponseRequest
		if err := c.ShouldBindJSON(&req); err != nil {
			c.JSON(http.StatusBadRequest, models.ErrorResponse{Error: err.Error()})
			return
		}
		if err := piClient.SendExtensionUIResponse(req.ID, req.Response); err != nil {
			c.JSON(http.StatusInternalServerError, models.ErrorResponse{Error: err.Error()})
			return
		}
		c.JSON(http.StatusOK, models.OKResponse{OK: true})
	})
}
