package bsontools

import (
	"fmt"
	"regexp"
	"strings"

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

func BuildCaseInsensitiveRegex(value string) bson.M {
	return bson.M{"$regex": primitive.Regex{
		Pattern: regexp.QuoteMeta(fmt.Sprintf(".*%s.*", regexp.QuoteMeta(strings.ToLower(value)))),
		Options: "i",
	}}
}
