func (wc *WriteConcern) WithOptions(options ...Option) *WriteConcern {
	if wc == nil {
		return New(options...)
	}
	newWC := &WriteConcern{}
	*newWC = *wc
	for _, option := range options {
		option(newWC)
	}
	return newWC
}
WithOptions returns a copy of this WriteConcern with the options set.
package writeconcern  
import (
	"errors"
	"time"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/bsontype"
	"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)
var ErrInconsistent = errors.New("a write concern cannot have both w=0 and j=true")
var ErrEmptyWriteConcern = errors.New("a write concern must have at least one field set")
var ErrNegativeW = errors.New("write concern `w` field cannot be a negative number")
var ErrNegativeWTimeout = errors.New("write concern `wtimeout` field cannot be negative")
type WriteConcern struct {
	w        interface{}
	j        bool
	wTimeout time.Duration
}
type Option func(concern *WriteConcern)
func New(options ...Option) *WriteConcern {
	concern := &WriteConcern{}
	for _, option := range options {
		option(concern)
	}
	return concern
}
func W(w int) Option {
	return func(concern *WriteConcern) {
		concern.w = w
	}
}
func WMajority() Option {
	return func(concern *WriteConcern) {
		concern.w = "majority"
	}
}
func WTagSet(tag string) Option {
	return func(concern *WriteConcern) {
		concern.w = tag
	}
}
func J(j bool) Option {
	return func(concern *WriteConcern) {
		concern.j = j
	}
}
func WTimeout(d time.Duration) Option {
	return func(concern *WriteConcern) {
		concern.wTimeout = d
	}
}
func (wc *WriteConcern) MarshalBSONValue() (bsontype.Type, []byte, error) {
	if !wc.IsValid() {
		return bsontype.Type(0), nil, ErrInconsistent
	}
	var elems []byte
	if wc.w != nil {
		switch t := wc.w.(type) {
		case int:
			if t < 0 {
				return bsontype.Type(0), nil, ErrNegativeW
			}
			elems = bsoncore.AppendInt32Element(elems, "w", int32(t))
		case string:
			elems = bsoncore.AppendStringElement(elems, "w", string(t))
		}
	}
	if wc.j {
		elems = bsoncore.AppendBooleanElement(elems, "j", wc.j)
	}
	if wc.wTimeout < 0 {
		return bsontype.Type(0), nil, ErrNegativeWTimeout
	}
	if wc.wTimeout != 0 {
		elems = bsoncore.AppendInt64Element(elems, "wtimeout", int64(wc.wTimeout/time.Millisecond))
	}
	if len(elems) == 0 {
		return bsontype.Type(0), nil, ErrEmptyWriteConcern
	}
	return bsontype.EmbeddedDocument, bsoncore.BuildDocument(nil, elems), nil
}
func AcknowledgedValue(rawv bson.RawValue) bool {
	doc, ok := bsoncore.Value{Type: rawv.Type, Data: rawv.Value}.DocumentOK()
	if !ok {
		return false
	}
	val, err := doc.LookupErr("w")
	if err != nil {
		return true
	}
	i32, ok := val.Int32OK()
	if !ok {
		return false
	}
	return i32 != 0
}
func (wc *WriteConcern) Acknowledged() bool {
	if wc == nil || wc.j {
		return true
	}
	switch v := wc.w.(type) {
	case int:
		if v == 0 {
			return false
		}
	}
	return true
}
func (wc *WriteConcern) IsValid() bool {
	if !wc.j {
		return true
	}
	switch v := wc.w.(type) {
	case int:
		if v == 0 {
			return false
		}
	}
	return true
}
func (wc *WriteConcern) GetW() interface{} {
	return wc.w
}
func (wc *WriteConcern) GetJ() bool {
	return wc.j
}
func (wc *WriteConcern) GetWTimeout() time.Duration {
	return wc.wTimeout
}