package redis

import (
	
	
	
)

// note: the APIs is experimental and may be subject to change.
type VectorSetCmdable interface {
	VAdd(ctx context.Context, key, element string, val Vector) *BoolCmd
	VAddWithArgs(ctx context.Context, key, element string, val Vector, addArgs *VAddArgs) *BoolCmd
	VCard(ctx context.Context, key string) *IntCmd
	VDim(ctx context.Context, key string) *IntCmd
	VEmb(ctx context.Context, key, element string, raw bool) *SliceCmd
	VGetAttr(ctx context.Context, key, element string) *StringCmd
	VInfo(ctx context.Context, key string) *MapStringInterfaceCmd
	VLinks(ctx context.Context, key, element string) *StringSliceSliceCmd
	VLinksWithScores(ctx context.Context, key, element string) *VectorScoreSliceSliceCmd
	VRandMember(ctx context.Context, key string) *StringCmd
	VRandMemberCount(ctx context.Context, key string, count int) *StringSliceCmd
	VRem(ctx context.Context, key, element string) *BoolCmd
	VSetAttr(ctx context.Context, key, element string, attr interface{}) *BoolCmd
	VClearAttributes(ctx context.Context, key, element string) *BoolCmd
	VSim(ctx context.Context, key string, val Vector) *StringSliceCmd
	VSimWithScores(ctx context.Context, key string, val Vector) *VectorScoreSliceCmd
	VSimWithArgs(ctx context.Context, key string, val Vector, args *VSimArgs) *StringSliceCmd
	VSimWithArgsWithScores(ctx context.Context, key string, val Vector, args *VSimArgs) *VectorScoreSliceCmd
	VSimWithArgsWithAttribs(ctx context.Context, key string, val Vector, args *VSimArgs) *VectorAttribSliceCmd
	VSimWithArgsWithScoresWithAttribs(ctx context.Context, key string, val Vector, args *VSimArgs) *VectorScoreAttribSliceCmd
	VRange(ctx context.Context, key, start, end string, count int64) *StringSliceCmd
	VIsMember(ctx context.Context, key, element string) *BoolCmd
}

type Vector interface {
	Value() []any
}

const (
	vectorFormatFP32   string = "FP32"
	vectorFormatValues string = "Values"
	vectorFormatF16    string = "FLOAT16"
	vectorFormatBF16   string = "BFLOAT16"
	vectorFormatF64    string = "FLOAT64"
	vectorFormatI8     string = "INT8"
	vectorFormatU8     string = "UINT8"
)

type VectorFP32 struct {
	Val []byte
}

func ( *VectorFP32) () []any {
	return []any{vectorFormatFP32, .Val}
}

var _ Vector = (*VectorFP32)(nil)

// VectorFloat16 represents a FLOAT16-encoded vector blob.
// note: intended for search/index query commands such as FT.HYBRID.
type VectorFloat16 struct {
	Val []byte
}

func ( *VectorFloat16) () []any {
	return []any{vectorFormatF16, .Val}
}

var _ Vector = (*VectorFloat16)(nil)

// VectorBFloat16 represents a BFLOAT16-encoded vector blob.
// note: intended for search/index query commands such as FT.HYBRID.
type VectorBFloat16 struct {
	Val []byte
}

func ( *VectorBFloat16) () []any {
	return []any{vectorFormatBF16, .Val}
}

var _ Vector = (*VectorBFloat16)(nil)

// VectorFloat64 represents a FLOAT64-encoded vector blob.
// note: intended for search/index query commands such as FT.HYBRID.
type VectorFloat64 struct {
	Val []byte
}

func ( *VectorFloat64) () []any {
	return []any{vectorFormatF64, .Val}
}

var _ Vector = (*VectorFloat64)(nil)

// VectorInt8 represents an INT8-encoded vector blob.
// note: intended for search/index query commands such as FT.HYBRID.
type VectorInt8 struct {
	Val []byte
}

func ( *VectorInt8) () []any {
	return []any{vectorFormatI8, .Val}
}

var _ Vector = (*VectorInt8)(nil)

// VectorUint8 represents a UINT8-encoded vector blob.
// note: intended for search/index query commands such as FT.HYBRID.
type VectorUint8 struct {
	Val []byte
}

func ( *VectorUint8) () []any {
	return []any{vectorFormatU8, .Val}
}

var _ Vector = (*VectorUint8)(nil)

type VectorValues struct {
	Val []float64
}

func ( *VectorValues) () []any {
	 := make([]any, 2+len(.Val))
	[0] = vectorFormatValues
	[1] = len(.Val)
	for ,  := range .Val {
		[2+] = 
	}
	return 
}

var _ Vector = (*VectorValues)(nil)

type VectorRef struct {
	Name string // the name of the referent vector
}

func ( *VectorRef) () []any {
	return []any{"ele", .Name}
}

var _ Vector = (*VectorRef)(nil)

type VectorScore struct {
	Name  string
	Score float64
}

type VectorAttrib struct {
	Name    string
	Attribs *string
}

type VectorScoreAttrib struct {
	Name    string
	Score   float64
	Attribs *string
}

// `VADD key (FP32 | VALUES num) vector element`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string,  Vector) *BoolCmd {
	return .VAddWithArgs(, , , , &VAddArgs{})
}

type VAddArgs struct {
	// the REDUCE option must be passed immediately after the key
	Reduce int64
	Cas    bool

	// The NoQuant, Q8 and Bin options are mutually exclusive.
	NoQuant bool
	Q8      bool
	Bin     bool

	EF      int64
	SetAttr string
	M       int64
}

func ( VAddArgs) () int64 {
	return .Reduce
}

func ( VAddArgs) ( []any) []any {
	if .Cas {
		 = append(, "cas")
	}

	if .NoQuant {
		 = append(, "noquant")
	} else if .Q8 {
		 = append(, "q8")
	} else if .Bin {
		 = append(, "bin")
	}

	if .EF > 0 {
		 = append(, "ef", strconv.FormatInt(.EF, 10))
	}
	if len(.SetAttr) > 0 {
		 = append(, "setattr", .SetAttr)
	}
	if .M > 0 {
		 = append(, "m", strconv.FormatInt(.M, 10))
	}
	return 
}

// `VADD key [REDUCE dim] (FP32 | VALUES num) vector element [CAS] [NOQUANT | Q8 | BIN] [EF build-exploration-factor] [SETATTR attributes] [M numlinks]`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string,  Vector,  *VAddArgs) *BoolCmd {
	if  == nil {
		 = &VAddArgs{}
	}
	 := []any{"vadd", }
	if .reduce() > 0 {
		 = append(, "reduce", .reduce())
	}
	 = append(, .Value()...)
	 = append(, )
	 = .appendArgs()
	 := NewBoolCmd(, ...)
	_ = (, )
	return 
}

// `VCARD key`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string) *IntCmd {
	 := NewIntCmd(, "vcard", )
	_ = (, )
	return 
}

// `VDIM key`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string) *IntCmd {
	 := NewIntCmd(, "vdim", )
	_ = (, )
	return 
}

// `VEMB key element [RAW]`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string,  bool) *SliceCmd {
	 := []any{"vemb", , }
	if  {
		 = append(, "raw")
	}
	 := NewSliceCmd(, ...)
	_ = (, )
	return 
}

// `VGETATTR key element`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string) *StringCmd {
	 := NewStringCmd(, "vgetattr", , )
	_ = (, )
	return 
}

// `VINFO key`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string) *MapStringInterfaceCmd {
	 := NewMapStringInterfaceCmd(, "vinfo", )
	_ = (, )
	return 
}

// `VLINKS key element`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string) *StringSliceSliceCmd {
	 := NewStringSliceSliceCmd(, "vlinks", , )
	_ = (, )
	return 
}

// `VLINKS key element WITHSCORES`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string) *VectorScoreSliceSliceCmd {
	 := NewVectorScoreSliceSliceCmd(, "vlinks", , , "withscores")
	_ = (, )
	return 
}

// `VRANDMEMBER key`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string) *StringCmd {
	 := NewStringCmd(, "vrandmember", )
	_ = (, )
	return 
}

// `VRANDMEMBER key [count]`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string,  int) *StringSliceCmd {
	 := NewStringSliceCmd(, "vrandmember", , )
	_ = (, )
	return 
}

// `VREM key element`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string) *BoolCmd {
	 := NewBoolCmd(, "vrem", , )
	_ = (, )
	return 
}

// `VSETATTR key element "{ JSON obj }"`
// The `attr` must be something that can be marshaled to JSON (using encoding/JSON) unless
// the argument is a string or []byte when we assume that it can be passed directly as JSON.
//
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string,  interface{}) *BoolCmd {
	var  string
	var  error
	switch v := .(type) {
	case string:
		 = 
	case []byte:
		 = string()
	default:
		var  []byte
		,  = json.Marshal()
		if  != nil {
			// If marshalling fails, create the command and set the error; this command won't be executed.
			 := NewBoolCmd(, "vsetattr", , , "")
			.SetErr()
			return 
		}
		 = string()
	}
	 := NewBoolCmd(, "vsetattr", , , )
	_ = (, )
	return 
}

// `VClearAttributes` clear attributes on a vector set element.
// The implementation of `VClearAttributes` is execute command `VSETATTR key element ""`.
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string) *BoolCmd {
	 := NewBoolCmd(, "vsetattr", , , "")
	_ = (, )
	return 
}

// `VSIM key (ELE | FP32 | VALUES num) (vector | element)`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string,  Vector) *StringSliceCmd {
	return .VSimWithArgs(, , , &VSimArgs{})
}

// `VSIM key (ELE | FP32 | VALUES num) (vector | element) WITHSCORES`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string,  Vector) *VectorScoreSliceCmd {
	return .VSimWithArgsWithScores(, , , &VSimArgs{})
}

type VSimArgs struct {
	Count    int64
	EF       int64
	Filter   string
	FilterEF int64
	Truth    bool
	NoThread bool
	Epsilon  float64
}

func ( VSimArgs) ( []any) []any {
	if .Count > 0 {
		 = append(, "count", .Count)
	}
	if .EF > 0 {
		 = append(, "ef", .EF)
	}
	if len(.Filter) > 0 {
		 = append(, "filter", .Filter)
	}
	if .FilterEF > 0 {
		 = append(, "filter-ef", .FilterEF)
	}
	if .Truth {
		 = append(, "truth")
	}
	if .NoThread {
		 = append(, "nothread")
	}
	if .Epsilon > 0 {
		 = append(, "epsilon", .Epsilon)
	}
	return 
}

// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [COUNT num] [EPSILON delta]
// [EF search-exploration-factor] [FILTER expression] [FILTER-EF max-filtering-effort] [TRUTH] [NOTHREAD]`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string,  Vector,  *VSimArgs) *StringSliceCmd {
	if  == nil {
		 = &VSimArgs{}
	}
	 := []any{"vsim", }
	 = append(, .Value()...)
	 = .appendArgs()
	 := NewStringSliceCmd(, ...)
	_ = (, )
	return 
}

// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [WITHSCORES] [COUNT num] [EPSILON delta]
// [EF search-exploration-factor] [FILTER expression] [FILTER-EF max-filtering-effort] [TRUTH] [NOTHREAD]`
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string,  Vector,  *VSimArgs) *VectorScoreSliceCmd {
	if  == nil {
		 = &VSimArgs{}
	}
	 := []any{"vsim", }
	 = append(, .Value()...)
	 = append(, "withscores")
	 = .appendArgs()
	 := NewVectorInfoSliceCmd(, ...)
	_ = (, )
	return 
}

// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [WITHATTRIBS] [COUNT num] [EPSILON delta]
// [EF search-exploration-factor] [FILTER expression] [FILTER-EF max-filtering-effort] [TRUTH] [NOTHREAD]`
// WITHATTRIBS is only available in Redis v8.2.0+
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string,  Vector,  *VSimArgs) *VectorAttribSliceCmd {
	if  == nil {
		 = &VSimArgs{}
	}
	 := []any{"vsim", }
	 = append(, .Value()...)
	 = append(, "withattribs")
	 = .appendArgs()
	 := NewVectorAttribSliceCmd(, ...)
	_ = (, )
	return 
}

// `VSIM key (ELE | FP32 | VALUES num) (vector | element) [WITHSCORES] [WITHATTRIBS] [COUNT num] [EPSILON delta]
// [EF search-exploration-factor] [FILTER expression] [FILTER-EF max-filtering-effort] [TRUTH] [NOTHREAD]`
// WITHATTRIBS is only available in Redis v8.2.0+
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context,  string,  Vector,  *VSimArgs) *VectorScoreAttribSliceCmd {
	if  == nil {
		 = &VSimArgs{}
	}
	 := []any{"vsim", }
	 = append(, .Value()...)
	 = append(, "withscores", "withattribs")
	 = .appendArgs()
	 := NewVectorScoreAttribSliceCmd(, ...)
	_ = (, )
	return 
}

// `VRANGE key start end count`
// a negative count means to return all the elements in the vector set.
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, , ,  string,  int64) *StringSliceCmd {
	 := []any{"vrange", , , , }
	 := NewStringSliceCmd(, ...)
	_ = (, )
	return 
}

// `VISMEMBER key element`
// Check if an element exists in a vector set.
// note: the API is experimental and may be subject to change.
func ( cmdable) ( context.Context, ,  string) *BoolCmd {
	 := NewBoolCmd(, "vismember", , )
	_ = (, )
	return 
}