package redis

import (
	
	
)

type BitMapCmdable interface {
	GetBit(ctx context.Context, key string, offset int64) *IntCmd
	SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd
	BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd
	BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpDiff(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpDiff1(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpAndOr(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpOne(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpNot(ctx context.Context, destKey string, key string) *IntCmd
	BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd
	BitPosSpan(ctx context.Context, key string, bit int8, start, end int64, span string) *IntCmd
	BitField(ctx context.Context, key string, values ...interface{}) *IntSliceCmd
	BitFieldRO(ctx context.Context, key string, values ...interface{}) *IntSliceCmd
}

func ( cmdable) ( context.Context,  string,  int64) *IntCmd {
	 := NewIntCmd(, "getbit", , )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  int64,  int) *IntCmd {
	 := NewIntCmd(
		,
		"setbit",
		,
		,
		,
	)
	_ = (, )
	return 
}

type BitCount struct {
	Start, End int64
	Unit       string // BYTE(default) | BIT
}

const BitCountIndexByte string = "BYTE"
const BitCountIndexBit string = "BIT"

func ( cmdable) ( context.Context,  string,  *BitCount) *IntCmd {
	 := make([]any, 2, 5)
	[0] = "bitcount"
	[1] = 
	if  != nil {
		 = append(, .Start, .End)
		if .Unit != "" {
			if .Unit != BitCountIndexByte && .Unit != BitCountIndexBit {
				 := NewIntCmd()
				.SetErr(errors.New("redis: invalid bitcount index"))
				return 
			}
			 = append(, .Unit)
		}
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, ,  string,  ...string) *IntCmd {
	 := make([]interface{}, 3+len())
	[0] = "bitop"
	[1] = 
	[2] = 
	for ,  := range  {
		[3+] = 
	}
	 := NewIntCmd(, ...)
	.SetFirstKeyPos(2) // the key is not args[1]: route by it
	_ = (, )
	return 
}

// BitOpAnd creates a new bitmap in which users are members of all given bitmaps
func ( cmdable) ( context.Context,  string,  ...string) *IntCmd {
	return .bitOp(, "and", , ...)
}

// BitOpOr creates a new bitmap in which users are member of at least one given bitmap
func ( cmdable) ( context.Context,  string,  ...string) *IntCmd {
	return .bitOp(, "or", , ...)
}

// BitOpXor creates a new bitmap in which users are the result of XORing all given bitmaps
func ( cmdable) ( context.Context,  string,  ...string) *IntCmd {
	return .bitOp(, "xor", , ...)
}

// BitOpNot creates a new bitmap in which users are not members of a given bitmap
func ( cmdable) ( context.Context,  string,  string) *IntCmd {
	return .bitOp(, "not", , )
}

// BitOpDiff creates a new bitmap in which users are members of bitmap X but not of any of bitmaps Y1, Y2, …
// Introduced with Redis 8.2
func ( cmdable) ( context.Context,  string,  ...string) *IntCmd {
	return .bitOp(, "diff", , ...)
}

// BitOpDiff1 creates a new bitmap in which users are members of one or more of bitmaps Y1, Y2, … but not members of bitmap X
// Introduced with Redis 8.2
func ( cmdable) ( context.Context,  string,  ...string) *IntCmd {
	return .bitOp(, "diff1", , ...)
}

// BitOpAndOr creates a new bitmap in which users are members of bitmap X and also members of one or more of bitmaps Y1, Y2, …
// Introduced with Redis 8.2
func ( cmdable) ( context.Context,  string,  ...string) *IntCmd {
	return .bitOp(, "andor", , ...)
}

// BitOpOne creates a new bitmap in which users are members of exactly one of the given bitmaps
// Introduced with Redis 8.2
func ( cmdable) ( context.Context,  string,  ...string) *IntCmd {
	return .bitOp(, "one", , ...)
}

// BitPos is an API before Redis version 7.0, cmd: bitpos key bit start end
// if you need the `byte | bit` parameter, please use `BitPosSpan`.
func ( cmdable) ( context.Context,  string,  int64,  ...int64) *IntCmd {
	 := make([]interface{}, 3+len())
	[0] = "bitpos"
	[1] = 
	[2] = 
	switch len() {
	case 0:
	case 1:
		[3] = [0]
	case 2:
		[3] = [0]
		[4] = [1]
	default:
		 := NewIntCmd()
		.SetErr(errors.New("too many arguments"))
		return 
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// BitPosSpan supports the `byte | bit` parameters in redis version 7.0,
// the bitpos command defaults to using byte type for the `start-end` range,
// which means it counts in bytes from start to end. you can set the value
// of "span" to determine the type of `start-end`.
// span = "bit", cmd: bitpos key bit start end bit
// span = "byte", cmd: bitpos key bit start end byte
func ( cmdable) ( context.Context,  string,  int8, ,  int64,  string) *IntCmd {
	 := NewIntCmd(, "bitpos", , , , , )
	_ = (, )
	return 
}

// BitField accepts multiple values:
//   - BitField("set", "i1", "offset1", "value1","cmd2", "type2", "offset2", "value2")
//   - BitField([]string{"cmd1", "type1", "offset1", "value1","cmd2", "type2", "offset2", "value2"})
//   - BitField([]interface{}{"cmd1", "type1", "offset1", "value1","cmd2", "type2", "offset2", "value2"})
func ( cmdable) ( context.Context,  string,  ...interface{}) *IntSliceCmd {
	 := make([]interface{}, 2, 2+len())
	[0] = "bitfield"
	[1] = 
	 = appendArgs(, )
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// BitFieldRO - Read-only variant of the BITFIELD command.
// It is like the original BITFIELD but only accepts GET subcommand and can safely be used in read-only replicas.
// - BitFieldRO(ctx, key, "<Encoding0>", "<Offset0>", "<Encoding1>","<Offset1>")
func ( cmdable) ( context.Context,  string,  ...interface{}) *IntSliceCmd {
	 := make([]interface{}, 2, 2+len())
	[0] = "BITFIELD_RO"
	[1] = 
	if len()%2 != 0 {
		 := NewIntSliceCmd()
		.SetErr(errors.New("BitFieldRO: invalid number of arguments, must be even"))
		return 
	}
	for  := 0;  < len();  += 2 {
		 = append(, "GET", [], [+1])
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}