package mongo

import (
	"crypto/sha256"
	"encoding/hex"

	"go.mongodb.org/mongo-driver/v2/bson"
)

// HashFilter returns a stable SHA-256 hex digest of a MongoDB filter for cursor binding.
func HashFilter(filter bson.M) string {
	if len(filter) == 0 {
		return ""
	}
	raw, err := bson.Marshal(filter)
	if err != nil {
		return ""
	}
	sum := sha256.Sum256(raw)
	return hex.EncodeToString(sum[:])
}
