package redis

import (
	
	
	
)

type ListCmdable interface {
	BLPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd
	BLMPop(ctx context.Context, timeout time.Duration, direction string, count int64, keys ...string) *KeyValuesCmd
	BRPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd
	BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd
	LIndex(ctx context.Context, key string, index int64) *StringCmd
	LInsert(ctx context.Context, key, op string, pivot, value interface{}) *IntCmd
	LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *IntCmd
	LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd
	LLen(ctx context.Context, key string) *IntCmd
	LMPop(ctx context.Context, direction string, count int64, keys ...string) *KeyValuesCmd
	LPop(ctx context.Context, key string) *StringCmd
	LPopCount(ctx context.Context, key string, count int) *StringSliceCmd
	LPos(ctx context.Context, key string, value string, args LPosArgs) *IntCmd
	LPosCount(ctx context.Context, key string, value string, count int64, args LPosArgs) *IntSliceCmd
	LPush(ctx context.Context, key string, values ...interface{}) *IntCmd
	LPushX(ctx context.Context, key string, values ...interface{}) *IntCmd
	LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
	LRem(ctx context.Context, key string, count int64, value interface{}) *IntCmd
	LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd
	LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd
	RPop(ctx context.Context, key string) *StringCmd
	RPopCount(ctx context.Context, key string, count int) *StringSliceCmd
	RPopLPush(ctx context.Context, source, destination string) *StringCmd
	RPush(ctx context.Context, key string, values ...interface{}) *IntCmd
	RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd
	LMove(ctx context.Context, source, destination, srcpos, destpos string) *StringCmd
	BLMove(ctx context.Context, source, destination, srcpos, destpos string, timeout time.Duration) *StringCmd
	LMoveM(ctx context.Context, source, destination, srcpos, destpos string, args LMoveMArgs) *StringSliceCmd
	BLMoveM(ctx context.Context, source, destination, srcpos, destpos string, timeout time.Duration, args LMoveMArgs) *StringSliceCmd
}

func ( cmdable) ( context.Context,  time.Duration,  ...string) *StringSliceCmd {
	 := make([]interface{}, 1+len()+1)
	[0] = "blpop"
	for ,  := range  {
		[1+] = 
	}
	[len()-1] = formatSec(, )
	 := NewStringSliceCmd(, ...)
	.setReadTimeout()
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  time.Duration,  string,  int64,  ...string) *KeyValuesCmd {
	 := make([]interface{}, 3+len(), 6+len())
	[0] = "blmpop"
	[1] = formatSec(, )
	[2] = len()
	for ,  := range  {
		[3+] = 
	}
	 = append(, strings.ToLower(), "count", )
	 := NewKeyValuesCmd(, ...)
	// The key follows numkeys, not args[1]: route by it.
	if len() > 0 {
		.SetFirstKeyPos(3)
	}
	.setReadTimeout()
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  time.Duration,  ...string) *StringSliceCmd {
	 := make([]interface{}, 1+len()+1)
	[0] = "brpop"
	for ,  := range  {
		[1+] = 
	}
	[len()+1] = formatSec(, )
	 := NewStringSliceCmd(, ...)
	.setReadTimeout()
	_ = (, )
	return 
}

// BRPopLPush pops an element from a list, pushes it to another list and returns it.
// Blocks until an element is available or timeout is reached.
//
// Deprecated: Use BLMove with RIGHT and LEFT arguments instead as of Redis 6.2.0.
func ( cmdable) ( context.Context, ,  string,  time.Duration) *StringCmd {
	 := NewStringCmd(
		,
		"brpoplpush",
		,
		,
		formatSec(, ),
	)
	.setReadTimeout()
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  int64) *StringCmd {
	 := NewStringCmd(, "lindex", , )
	_ = (, )
	return 
}

// LMPop Pops one or more elements from the first non-empty list key from the list of provided key names.
// direction: left or right, count: > 0
// example: client.LMPop(ctx, "left", 3, "key1", "key2")
func ( cmdable) ( context.Context,  string,  int64,  ...string) *KeyValuesCmd {
	 := make([]interface{}, 2+len(), 5+len())
	[0] = "lmpop"
	[1] = len()
	for ,  := range  {
		[2+] = 
	}
	 = append(, strings.ToLower(), "count", )
	 := NewKeyValuesCmd(, ...)
	// The key follows numkeys, not args[1]: route by it.
	if len() > 0 {
		.SetFirstKeyPos(2)
	}
	_ = (, )
	return 
}

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

func ( cmdable) ( context.Context,  string, ,  interface{}) *IntCmd {
	 := NewIntCmd(, "linsert", , "before", , )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string, ,  interface{}) *IntCmd {
	 := NewIntCmd(, "linsert", , "after", , )
	_ = (, )
	return 
}

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

func ( cmdable) ( context.Context,  string) *StringCmd {
	 := NewStringCmd(, "lpop", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  int) *StringSliceCmd {
	 := NewStringSliceCmd(, "lpop", , )
	_ = (, )
	return 
}

type LPosArgs struct {
	Rank, MaxLen int64
}

// LMoveMMode is the count semantics for LMOVEM/BLMOVEM.
type LMoveMMode string

const (
	LMoveMCount   LMoveMMode = "COUNT"   // up to Count
	LMoveMExactly LMoveMMode = "EXACTLY" // exactly Count, or nothing
)

// LMoveMOrder is the destination ordering for LMOVEM/BLMOVEM.
type LMoveMOrder string

const (
	LMoveMOBO  LMoveMOrder = "OBO"  // one-by-one, order reversed
	LMoveMBulk LMoveMOrder = "BULK" // preserve order
)

// LMoveMArgs configures the optional count group of LMOVEM/BLMOVEM.
// Count <= 0 moves a single element. Mode defaults to COUNT, Order to BULK.
type LMoveMArgs struct {
	Mode  LMoveMMode
	Count int64
	Order LMoveMOrder
}

func ( LMoveMArgs) ( []interface{}) []interface{} {
	if .Count <= 0 {
		return 
	}
	 := .Mode
	if  == "" {
		 = LMoveMCount
	}
	 := .Order
	if  == "" {
		 = LMoveMBulk
	}
	return append(, string(), .Count, string())
}

func ( cmdable) ( context.Context,  string,  string,  LPosArgs) *IntCmd {
	 := []interface{}{"lpos", , }
	if .Rank != 0 {
		 = append(, "rank", .Rank)
	}
	if .MaxLen != 0 {
		 = append(, "maxlen", .MaxLen)
	}

	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  string,  int64,  LPosArgs) *IntSliceCmd {
	 := []interface{}{"lpos", , , "count", }
	if .Rank != 0 {
		 = append(, "rank", .Rank)
	}
	if .MaxLen != 0 {
		 = append(, "maxlen", .MaxLen)
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  ...interface{}) *IntCmd {
	 := make([]interface{}, 2, 2+len())
	[0] = "lpush"
	[1] = 
	 = appendArgs(, )
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  ...interface{}) *IntCmd {
	 := make([]interface{}, 2, 2+len())
	[0] = "lpushx"
	[1] = 
	 = appendArgs(, )
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string, ,  int64) *StringSliceCmd {
	 := NewStringSliceCmd(
		,
		"lrange",
		,
		,
		,
	)
	_ = (, )
	return 
}

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

func ( cmdable) ( context.Context,  string,  int64,  interface{}) *StatusCmd {
	 := NewStatusCmd(, "lset", , , )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string, ,  int64) *StatusCmd {
	 := NewStatusCmd(
		,
		"ltrim",
		,
		,
		,
	)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *StringCmd {
	 := NewStringCmd(, "rpop", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  int) *StringSliceCmd {
	 := NewStringSliceCmd(, "rpop", , )
	_ = (, )
	return 
}

// RPopLPush atomically returns and removes the last element of the source list,
// and pushes the element as the first element of the destination list.
//
// Deprecated: Use LMove with RIGHT and LEFT arguments instead as of Redis 6.2.0.
func ( cmdable) ( context.Context, ,  string) *StringCmd {
	 := NewStringCmd(, "rpoplpush", , )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  ...interface{}) *IntCmd {
	 := make([]interface{}, 2, 2+len())
	[0] = "rpush"
	[1] = 
	 = appendArgs(, )
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  ...interface{}) *IntCmd {
	 := make([]interface{}, 2, 2+len())
	[0] = "rpushx"
	[1] = 
	 = appendArgs(, )
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, , , ,  string) *StringCmd {
	 := NewStringCmd(, "lmove", , , , )
	_ = (, )
	return 
}

func ( cmdable) (
	 context.Context, , , ,  string,  time.Duration,
) *StringCmd {
	 := NewStringCmd(, "blmove", , , , , formatSec(, ))
	.setReadTimeout()
	_ = (, )
	return 
}

// LMoveM atomically moves multiple elements between lists (Redis 8.10+).
// srcpos/destpos are "LEFT" or "RIGHT". Returns moved elements, or redis.Nil if none.
func ( cmdable) ( context.Context, , , ,  string,  LMoveMArgs) *StringSliceCmd {
	 := make([]interface{}, 5, 8)
	[0], [1], [2], [3], [4] = "lmovem", , , , 
	 = .appendArgs()
	 := NewStringSliceCmd(, ...)
	_ = (, )
	return 
}

// BLMoveM is the blocking variant of LMoveM (Redis 8.10+); timeout 0 blocks forever.
// Returns moved elements, or redis.Nil on timeout.
func ( cmdable) ( context.Context, , , ,  string,  time.Duration,  LMoveMArgs) *StringSliceCmd {
	 := make([]interface{}, 6, 9)
	[0], [1], [2], [3], [4] = "blmovem", , , , 
	[5] = formatSec(, )
	 = .appendArgs()
	 := NewStringSliceCmd(, ...)
	.setReadTimeout()
	_ = (, )
	return 
}