package search

import (
	"hyapp-admin-server/internal/modules/shared"
	"hyapp-admin-server/internal/repository"
)

type SearchService struct {
	store *repository.Store
}

func NewService(store *repository.Store) *SearchService {
	return &SearchService{store: store}
}

func (s *SearchService) Search(keyword string, actor shared.Actor) ([]repository.SearchResult, error) {
	access, err := s.store.DataAccessForUser(actor.UserID)
	if err != nil {
		return nil, err
	}
	return s.store.SearchWithAccess(keyword, actor.Permissions, access)
}
