package search

import (
	"github.com/gin-gonic/gin"
	"hyapp-admin-server/internal/modules/shared"
	"hyapp-admin-server/internal/repository"
	"hyapp-admin-server/internal/response"
)

type Handler struct {
	service *SearchService
}

func New(store *repository.Store) *Handler {
	return &Handler{service: NewService(store)}
}

func (h *Handler) Search(c *gin.Context) {
	// 搜索结果在 repository 层按权限裁剪，避免跨模块入口绕过菜单权限。
	results, err := h.service.Search(c.Query("keyword"), shared.ActorFromContext(c))
	if err != nil {
		response.ServerError(c, "搜索失败")
		return
	}
	response.OK(c, results)
}
