package redis

import (
	
	
	
	

	
)

// XTrimLimitDisabled is a sentinel value for the LIMIT argument of stream
// trimming (XAddArgs.Limit and the XTrim*Approx* commands). Passing it emits
// an explicit "LIMIT 0", which tells Redis to disable the trimming effort cap
// entirely. This differs from passing 0, which keeps the historical behavior:
// no LIMIT clause is sent and Redis applies its implicit default
// (100 * stream-node-max-entries examined entries).
//
// LIMIT is only valid together with the "~" (approximate) trimming flag;
// Redis rejects LIMIT used with exact ("=") trimming.
const XTrimLimitDisabled = -1

// appendXTrimLimit appends the LIMIT clause used by XADD and XTRIM trimming:
//   - limit > 0 emits "LIMIT <limit>";
//   - limit < 0 (see XTrimLimitDisabled) emits "LIMIT 0", disabling the
//     trimming effort cap;
//   - limit == 0 omits the clause, so Redis applies its implicit default.
func appendXTrimLimit( []interface{},  int64) []interface{} {
	switch {
	case  > 0:
		return append(, "limit", )
	case  < 0:
		return append(, "limit", int64(0))
	default:
		return 
	}
}

type StreamCmdable interface {
	XAdd(ctx context.Context, a *XAddArgs) *StringCmd
	XAckDel(ctx context.Context, stream string, group string, mode string, ids ...string) *SliceCmd
	XDel(ctx context.Context, stream string, ids ...string) *IntCmd
	XDelEx(ctx context.Context, stream string, mode string, ids ...string) *SliceCmd
	XLen(ctx context.Context, stream string) *IntCmd
	XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd
	XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd
	XRevRange(ctx context.Context, stream string, start, stop string) *XMessageSliceCmd
	XRevRangeN(ctx context.Context, stream string, start, stop string, count int64) *XMessageSliceCmd
	XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd
	XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd
	XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd
	XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd
	XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd
	XGroupDestroy(ctx context.Context, stream, group string) *IntCmd
	XGroupCreateConsumer(ctx context.Context, stream, group, consumer string) *IntCmd
	XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd
	XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd
	XAck(ctx context.Context, stream, group string, ids ...string) *IntCmd
	XNack(ctx context.Context, a *XNackArgs) *IntCmd
	XPending(ctx context.Context, stream, group string) *XPendingCmd
	XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd
	XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd
	XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd
	XAutoClaim(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimCmd
	XAutoClaimWithDeleted(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimWithDeletedCmd
	XAutoClaimJustID(ctx context.Context, a *XAutoClaimArgs) *XAutoClaimJustIDCmd
	XTrimMaxLen(ctx context.Context, key string, maxLen int64) *IntCmd
	XTrimMaxLenApprox(ctx context.Context, key string, maxLen, limit int64) *IntCmd
	XTrimMaxLenMode(ctx context.Context, key string, maxLen int64, mode string) *IntCmd
	XTrimMaxLenApproxMode(ctx context.Context, key string, maxLen, limit int64, mode string) *IntCmd
	XTrimMinID(ctx context.Context, key string, minID string) *IntCmd
	XTrimMinIDApprox(ctx context.Context, key string, minID string, limit int64) *IntCmd
	XTrimMinIDMode(ctx context.Context, key string, minID string, mode string) *IntCmd
	XTrimMinIDApproxMode(ctx context.Context, key string, minID string, limit int64, mode string) *IntCmd
	XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd
	XInfoStream(ctx context.Context, key string) *XInfoStreamCmd
	XInfoStreamFull(ctx context.Context, key string, count int) *XInfoStreamFullCmd
	XInfoConsumers(ctx context.Context, key string, group string) *XInfoConsumersCmd
	XCfgSet(ctx context.Context, a *XCfgSetArgs) *StatusCmd
}

// XAddArgs accepts values in the following formats:
//   - XAddArgs.Values = []interface{}{"key1", "value1", "key2", "value2"}
//   - XAddArgs.Values = []string("key1", "value1", "key2", "value2")
//   - XAddArgs.Values = map[string]interface{}{"key1": "value1", "key2": "value2"}
//
// Note that map will not preserve the order of key-value pairs.
// MaxLen/MaxLenApprox and MinID are in conflict, only one of them can be used.
//
// For idempotent production (at-most-once production):
//   - ProducerID: A unique identifier for the producer (required for both IDMP and IDMPAUTO)
//   - IdempotentID: A unique identifier for the message (used with IDMP)
//   - IdempotentAuto: If true, Redis will auto-generate an idempotent ID based on message content (IDMPAUTO)
//
// ProducerID and IdempotentID are mutually exclusive with IdempotentAuto.
// When using idempotent production, ID must be "*" or empty.
type XAddArgs struct {
	Stream     string
	NoMkStream bool
	MaxLen     int64 // MAXLEN N
	MinID      string
	// Approx causes MaxLen and MinID to use "~" matcher (instead of "=").
	Approx bool
	// Limit caps the trimming effort:
	//   - 0 omits the LIMIT clause (Redis applies its implicit default);
	//   - a positive value emits "LIMIT <n>";
	//   - a negative value (see XTrimLimitDisabled) emits "LIMIT 0",
	//     disabling the effort cap entirely.
	// LIMIT requires Approx to be true; Redis rejects LIMIT together with
	// exact ("=") trimming.
	Limit          int64
	Mode           string
	ID             string
	Values         interface{}
	ProducerID     string // Producer ID for idempotent production (IDMP or IDMPAUTO)
	IdempotentID   string // Idempotent ID for IDMP
	IdempotentAuto bool   // Use IDMPAUTO to auto-generate idempotent ID based on content
}

func ( cmdable) ( context.Context,  *XAddArgs) *StringCmd {
	 := make([]interface{}, 0, 15)
	 = append(, "xadd", .Stream)
	if .NoMkStream {
		 = append(, "nomkstream")
	}

	if .Mode != "" {
		 = append(, .Mode)
	}

	if .ProducerID != "" {
		if .IdempotentAuto {
			// IDMPAUTO pid
			 = append(, "idmpauto", .ProducerID)
		} else if .IdempotentID != "" {
			// IDMP pid iid
			 = append(, "idmp", .ProducerID, .IdempotentID)
		}
	}

	switch {
	case .MaxLen > 0:
		if .Approx {
			 = append(, "maxlen", "~", .MaxLen)
		} else {
			 = append(, "maxlen", "=", .MaxLen)
		}
	case .MinID != "":
		if .Approx {
			 = append(, "minid", "~", .MinID)
		} else {
			 = append(, "minid", "=", .MinID)
		}
	}
	 = appendXTrimLimit(, .Limit)

	if .ID != "" {
		 = append(, .ID)
	} else {
		 = append(, "*")
	}
	 = appendArg(, .Values)

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

func ( cmdable) ( context.Context,  string,  string,  string,  ...string) *SliceCmd {
	 := []interface{}{"xackdel", , , , "ids", len()}
	for ,  := range  {
		 = append(, )
	}
	 := NewSliceCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  ...string) *IntCmd {
	 := []interface{}{"xdel", }
	for ,  := range  {
		 = append(, )
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  string,  ...string) *SliceCmd {
	 := []interface{}{"xdelex", , , "ids", len()}
	for ,  := range  {
		 = append(, )
	}
	 := NewSliceCmd(, ...)
	_ = (, )
	return 
}

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

func ( cmdable) ( context.Context, , ,  string) *XMessageSliceCmd {
	 := NewXMessageSliceCmd(, "xrange", , , )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, , ,  string,  int64) *XMessageSliceCmd {
	 := NewXMessageSliceCmd(, "xrange", , , , "count", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, , ,  string) *XMessageSliceCmd {
	 := NewXMessageSliceCmd(, "xrevrange", , , )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, , ,  string,  int64) *XMessageSliceCmd {
	 := NewXMessageSliceCmd(, "xrevrange", , , , "count", )
	_ = (, )
	return 
}

type XReadArgs struct {
	Streams  []string // list of streams and ids, e.g. stream1 stream2 id1 id2
	Count    int64
	MaxCount int64 // cumulative cap on total entries across all streams (Redis >= 8.10)
	MaxSize  int64 // soft cumulative cap on total reply size in bytes across all streams (Redis >= 8.10)
	Block    time.Duration
	ID       string
}

func ( cmdable) ( context.Context,  *XReadArgs) *XStreamSliceCmd {
	 := make([]interface{}, 0, 2*len(.Streams)+10)
	 = append(, "xread")

	 := int8(1)
	if .Count > 0 {
		 = append(, "count")
		 = append(, .Count)
		 += 2
	}
	if .MaxCount > 0 {
		 = append(, "maxcount", .MaxCount)
		 += 2
	}
	if .MaxSize > 0 {
		 = append(, "maxsize", .MaxSize)
		 += 2
	}
	if .Block >= 0 {
		 = append(, "block")
		 = append(, int64(.Block/time.Millisecond))
		 += 2
	}
	 = append(, "streams")
	++
	for ,  := range .Streams {
		 = append(, )
	}
	if .ID != "" {
		for range .Streams {
			 = append(, .ID)
		}
	}

	 := NewXStreamSliceCmd(, ...)
	if .Block >= 0 {
		.setReadTimeout(.Block)
	}
	.SetFirstKeyPos()
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  ...string) *XStreamSliceCmd {
	return .XRead(, &XReadArgs{
		Streams: ,
		Block:   -1,
	})
}

func ( cmdable) ( context.Context, , ,  string) *StatusCmd {
	 := NewStatusCmd(, "xgroup", "create", , , )
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, , ,  string) *StatusCmd {
	 := NewStatusCmd(, "xgroup", "create", , , , "mkstream")
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, , ,  string) *StatusCmd {
	 := NewStatusCmd(, "xgroup", "setid", , , )
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, ,  string) *IntCmd {
	 := NewIntCmd(, "xgroup", "destroy", , )
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, , ,  string) *IntCmd {
	 := NewIntCmd(, "xgroup", "createconsumer", , , )
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, , ,  string) *IntCmd {
	 := NewIntCmd(, "xgroup", "delconsumer", , , )
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}

type XReadGroupArgs struct {
	Group    string
	Consumer string
	Streams  []string // list of streams and ids, e.g. stream1 stream2 id1 id2
	Count    int64
	MaxCount int64 // cumulative cap on total entries across all streams (Redis >= 8.10)
	MaxSize  int64 // soft cumulative cap on total reply size in bytes across all streams (Redis >= 8.10)
	Block    time.Duration
	NoAck    bool
	Claim    time.Duration // Claim idle pending entries older than this duration
}

func ( cmdable) ( context.Context,  *XReadGroupArgs) *XStreamSliceCmd {
	 := make([]interface{}, 0, 14+len(.Streams))
	 = append(, "xreadgroup", "group", .Group, .Consumer)

	 := int8(4)
	if .Count > 0 {
		 = append(, "count", .Count)
		 += 2
	}
	if .MaxCount > 0 {
		 = append(, "maxcount", .MaxCount)
		 += 2
	}
	if .MaxSize > 0 {
		 = append(, "maxsize", .MaxSize)
		 += 2
	}
	if .Block >= 0 {
		 = append(, "block", int64(.Block/time.Millisecond))
		 += 2
	}
	if .NoAck {
		 = append(, "noack")
		++
	}
	if .Claim > 0 {
		 = append(, "claim", int64(.Claim/time.Millisecond))
		 += 2
	}
	 = append(, "streams")
	++
	for ,  := range .Streams {
		 = append(, )
	}

	 := NewXStreamSliceCmd(, ...)
	if .Block >= 0 {
		.setReadTimeout(.Block)
	}
	.SetFirstKeyPos()
	_ = (, )

	// Record stream lag for each message (if command succeeded). Gated on the
	// result being readable WITHOUT blocking: this command carries a
	// read-timeout marker, so on the deferred autopipeline face it is diverted
	// and still running when we get here — and the default Block: 0 form can
	// wait indefinitely for messages, so reading the outcome would block the
	// submit call instead of returning a future (review finding by codex on
	// #3942). Skipped for a submission that has not executed yet; emitting
	// this from the execution path is a follow-up in the OTel wiring.
	if otel.Enabled() && .resultReady() && .rawErr() == nil {
		 := .Val()
		for ,  := range  {
			for ,  := range .Messages {
				// Parse message ID to extract timestamp (format: "millisecondsTime-sequenceNumber")
				if  := strings.SplitN(.ID, "-", 2); len() == 2 {
					if ,  := strconv.ParseInt([0], 10, 64);  == nil {
						// Calculate lag (time since message was created)
						 := time.Unix(0, *int64(time.Millisecond))
						 := time.Since()
						// Record lag metric
						otel.RecordStreamLag(, , nil, .Stream, .Group, .Consumer)
					}
				}
			}
		}
	}

	return 
}

func ( cmdable) ( context.Context, ,  string,  ...string) *IntCmd {
	 := []interface{}{"xack", , }
	for ,  := range  {
		 = append(, )
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// XNACK modes. See [XNackArgs.Mode].
const (
	XNackModeSilent = "SILENT"
	XNackModeFail   = "FAIL"
	XNackModeFatal  = "FATAL"
)

// XNackArgs represents the arguments for the XNACK command (Redis >= 8.8).
//
// XNACK negatively acknowledges one or more messages in a consumer group's
// Pending Entries List (PEL), releasing them back to the group so they can be
// redelivered to another consumer via XREADGROUP.
type XNackArgs struct {
	Stream string
	Group  string

	// Mode controls how the delivery counter is adjusted for each NACKed entry.
	// Must be one of [XNackModeSilent], [XNackModeFail], or [XNackModeFatal]:
	//   - SILENT: the consumer is shutting down or experiencing internal errors
	//     unrelated to the message. The delivery counter is decremented by 1,
	//     undoing the increment that happened when the message was delivered.
	//   - FAIL: the consumer could not process the message (e.g. insufficient
	//     memory), but another consumer might succeed. The delivery counter is
	//     left unchanged.
	//   - FATAL: the message is invalid or suspected malicious. The delivery
	//     counter is set to MAXINT, which will immediately move the message to
	//     the Dead Letter Queue (DLQ) if one is configured for the group.
	Mode string

	// IDs is the list of message IDs to NACK. All IDs must already be in the
	// group's PEL (i.e. previously delivered via XREADGROUP), unless Force is set.
	IDs []string

	// RetryCount sets the delivery counter to an explicit value, overriding the
	// counter adjustment that would otherwise be applied by Mode.
	// Leave nil to let Mode control the counter (the common case).
	RetryCount *uint64

	// Force allows NACKing message IDs that are not yet in the group's PEL,
	// creating new unowned NACKed PEL entries for them directly.
	// This is analogous to the FORCE flag in XCLAIM.
	// Primarily used internally by Redis during AOF rewrite to reconstruct
	// NACKed entries, but can also be used to manually inject entries.
	Force bool
}

// XNack executes the XNACK command. See [XNackArgs] for the full argument documentation.
// Requires Redis >= 8.8.
func ( cmdable) ( context.Context,  *XNackArgs) *IntCmd {
	 := make([]interface{}, 0, 9+len(.IDs))
	 = append(, "xnack", .Stream, .Group, .Mode, "ids", len(.IDs))
	for ,  := range .IDs {
		 = append(, )
	}
	if .RetryCount != nil {
		 = append(, "retrycount", *.RetryCount)
	}
	if .Force {
		 = append(, "force")
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, ,  string) *XPendingCmd {
	 := NewXPendingCmd(, "xpending", , )
	_ = (, )
	return 
}

type XPendingExtArgs struct {
	Stream   string
	Group    string
	Idle     time.Duration
	Start    string
	End      string
	Count    int64
	Consumer string
}

func ( cmdable) ( context.Context,  *XPendingExtArgs) *XPendingExtCmd {
	 := make([]interface{}, 0, 9)
	 = append(, "xpending", .Stream, .Group)
	if .Idle != 0 {
		 = append(, "idle", formatMs(, .Idle))
	}
	 = append(, .Start, .End, .Count)
	if .Consumer != "" {
		 = append(, .Consumer)
	}
	 := NewXPendingExtCmd(, ...)
	_ = (, )
	return 
}

type XAutoClaimArgs struct {
	Stream   string
	Group    string
	MinIdle  time.Duration
	Start    string
	Count    int64
	Consumer string
}

func ( cmdable) ( context.Context,  *XAutoClaimArgs) *XAutoClaimCmd {
	 := xAutoClaimArgs(, )
	 := NewXAutoClaimCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  *XAutoClaimArgs) *XAutoClaimWithDeletedCmd {
	 := xAutoClaimArgs(, )
	 := NewXAutoClaimWithDeletedCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  *XAutoClaimArgs) *XAutoClaimJustIDCmd {
	 := xAutoClaimArgs(, )
	 = append(, "justid")
	 := NewXAutoClaimJustIDCmd(, ...)
	_ = (, )
	return 
}

func xAutoClaimArgs( context.Context,  *XAutoClaimArgs) []interface{} {
	 := make([]interface{}, 0, 8)
	 = append(, "xautoclaim", .Stream, .Group, .Consumer, formatMs(, .MinIdle), .Start)
	if .Count > 0 {
		 = append(, "count", .Count)
	}
	return 
}

type XClaimArgs struct {
	Stream   string
	Group    string
	Consumer string
	MinIdle  time.Duration
	Messages []string
}

func ( cmdable) ( context.Context,  *XClaimArgs) *XMessageSliceCmd {
	 := xClaimArgs()
	 := NewXMessageSliceCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  *XClaimArgs) *StringSliceCmd {
	 := xClaimArgs()
	 = append(, "justid")
	 := NewStringSliceCmd(, ...)
	_ = (, )
	return 
}

func xClaimArgs( *XClaimArgs) []interface{} {
	 := make([]interface{}, 0, 5+len(.Messages))
	 = append(,
		"xclaim",
		.Stream,
		.Group, .Consumer,
		int64(.MinIdle/time.Millisecond))
	for ,  := range .Messages {
		 = append(, )
	}
	return 
}

// TODO: refactor xTrim, xTrimMode and the wrappers over the functions

// xTrim If approx is true, add the "~" parameter, otherwise it is the default "=" (redis default).
// example:
//
//	XTRIM key MAXLEN/MINID threshold LIMIT limit.
//	XTRIM key MAXLEN/MINID ~ threshold LIMIT limit.
//
// The redis-server version is lower than 6.2, please set limit to 0.
//
// limit == 0 omits the LIMIT clause, a positive limit emits "LIMIT <limit>",
// and a negative limit (see XTrimLimitDisabled) emits "LIMIT 0" to disable
// the trimming effort cap. LIMIT requires approx; Redis rejects it otherwise.
func ( cmdable) (
	 context.Context, ,  string,
	 bool,  interface{},  int64,
) *IntCmd {
	 := make([]interface{}, 0, 7)
	 = append(, "xtrim", , )
	if  {
		 = append(, "~")
	} else {
		 = append(, "=")
	}
	 = append(, )
	 = appendXTrimLimit(, )
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// XTrimMaxLen No `~` rules are used, `limit` cannot be used.
// cmd: XTRIM key MAXLEN maxLen
func ( cmdable) ( context.Context,  string,  int64) *IntCmd {
	return .xTrim(, , "maxlen", false, , 0)
}

// XTrimMaxLenApprox trims the stream using the `~` rule.
// cmd: XTRIM key MAXLEN ~ maxLen [LIMIT limit]
//
// limit == 0 omits the LIMIT clause, limit > 0 emits "LIMIT <limit>", and a
// negative limit (see XTrimLimitDisabled) emits "LIMIT 0" to disable the
// trimming effort cap.
func ( cmdable) ( context.Context,  string, ,  int64) *IntCmd {
	return .xTrim(, , "maxlen", true, , )
}

func ( cmdable) ( context.Context,  string,  string) *IntCmd {
	return .xTrim(, , "minid", false, , 0)
}

// XTrimMinIDApprox trims the stream using the `~` rule.
// cmd: XTRIM key MINID ~ minID [LIMIT limit]
//
// limit == 0 omits the LIMIT clause, limit > 0 emits "LIMIT <limit>", and a
// negative limit (see XTrimLimitDisabled) emits "LIMIT 0" to disable the
// trimming effort cap.
func ( cmdable) ( context.Context,  string,  string,  int64) *IntCmd {
	return .xTrim(, , "minid", true, , )
}

// xTrimMode is xTrim with a trailing trimming mode argument (e.g. KEEPREF).
// The limit semantics are the same as xTrim's.
func ( cmdable) (
	 context.Context, ,  string,
	 bool,  interface{},  int64,
	 string,
) *IntCmd {
	 := make([]interface{}, 0, 7)
	 = append(, "xtrim", , )
	if  {
		 = append(, "~")
	} else {
		 = append(, "=")
	}
	 = append(, )
	 = appendXTrimLimit(, )
	 = append(, )
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  int64,  string) *IntCmd {
	return .xTrimMode(, , "maxlen", false, , 0, )
}

func ( cmdable) ( context.Context,  string, ,  int64,  string) *IntCmd {
	return .xTrimMode(, , "maxlen", true, , , )
}

func ( cmdable) ( context.Context,  string,  string,  string) *IntCmd {
	return .xTrimMode(, , "minid", false, , 0, )
}

func ( cmdable) ( context.Context,  string,  string,  int64,  string) *IntCmd {
	return .xTrimMode(, , "minid", true, , , )
}

func ( cmdable) ( context.Context,  string,  string) *XInfoConsumersCmd {
	 := NewXInfoConsumersCmd(, , )
	.SetFirstKeyPos(2) // the key is not args[1]: route by it
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *XInfoGroupsCmd {
	 := NewXInfoGroupsCmd(, )
	.SetFirstKeyPos(2) // the key is not args[1]: route by it
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *XInfoStreamCmd {
	 := NewXInfoStreamCmd(, )
	.SetFirstKeyPos(2) // the key is not args[1]: route by it
	_ = (, )
	return 
}

// XInfoStreamFull XINFO STREAM FULL [COUNT count]
// redis-server >= 6.0.
func ( cmdable) ( context.Context,  string,  int) *XInfoStreamFullCmd {
	 := make([]interface{}, 0, 6)
	 = append(, "xinfo", "stream", , "full")
	if  > 0 {
		 = append(, "count", )
	}
	 := NewXInfoStreamFullCmd(, ...)
	.SetFirstKeyPos(2) // the key is not args[1]: route by it
	_ = (, )
	return 
}

// XCfgSetArgs represents the arguments for the XCFGSET command.
// Duration is the duration, in seconds, that Redis keeps each idempotent ID.
// MaxSize is the maximum number of most recent idempotent IDs that Redis keeps for each producer ID.
type XCfgSetArgs struct {
	Stream   string
	Duration int64
	MaxSize  int64
}

// XCfgSet sets the idempotent production configuration for a stream.
// XCFGSET key [IDMP-DURATION duration] [IDMP-MAXSIZE maxsize]
func ( cmdable) ( context.Context,  *XCfgSetArgs) *StatusCmd {
	 := make([]interface{}, 0, 6)
	 = append(, "xcfgset", .Stream)
	if .Duration > 0 {
		 = append(, "idmp-duration", .Duration)
	}
	if .MaxSize > 0 {
		 = append(, "idmp-maxsize", .MaxSize)
	}
	 := NewStatusCmd(, ...)
	_ = (, )
	return 
}