package engine

import (
	ahocorasick "github.com/petar-dambovaliev/aho-corasick"
	"github.com/salvacybersec/keyhunter/pkg/types"
)

// KeywordFilter filters a stream of chunks using an Aho-Corasick automaton.
// Only chunks that contain at least one provider keyword are sent to out.
// This is Stage 2 of the pipeline (runs after Source, before Detector).
func KeywordFilter(ac ahocorasick.AhoCorasick, in <-chan types.Chunk, out chan<- types.Chunk) {
	for chunk := range in {
		if len(ac.FindAll(string(chunk.Data))) > 0 {
			out <- chunk
		}
	}
}
