package redis

import (
	
	
)

type HashCmdable interface {
	HDel(ctx context.Context, key string, fields ...string) *IntCmd
	HExists(ctx context.Context, key, field string) *BoolCmd
	HGet(ctx context.Context, key, field string) *StringCmd
	HGetAll(ctx context.Context, key string) *MapStringStringCmd
	HGetDel(ctx context.Context, key string, fields ...string) *StringSliceCmd
	HGetEX(ctx context.Context, key string, fields ...string) *StringSliceCmd
	HGetEXWithArgs(ctx context.Context, key string, options *HGetEXOptions, fields ...string) *StringSliceCmd
	HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd
	HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd
	HKeys(ctx context.Context, key string) *StringSliceCmd
	HLen(ctx context.Context, key string) *IntCmd
	HMGet(ctx context.Context, key string, fields ...string) *SliceCmd
	HSet(ctx context.Context, key string, values ...interface{}) *IntCmd
	HMSet(ctx context.Context, key string, values ...interface{}) *BoolCmd
	HSetEX(ctx context.Context, key string, fieldsAndValues ...string) *IntCmd
	HSetEXWithArgs(ctx context.Context, key string, options *HSetEXOptions, fieldsAndValues ...string) *IntCmd
	HSetNX(ctx context.Context, key, field string, value interface{}) *BoolCmd
	HScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
	HScanNoValues(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
	HVals(ctx context.Context, key string) *StringSliceCmd
	HRandField(ctx context.Context, key string, count int) *StringSliceCmd
	HRandFieldWithValues(ctx context.Context, key string, count int) *KeyValueSliceCmd
	HStrLen(ctx context.Context, key, field string) *IntCmd
	HExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd
	HExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
	HPExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd
	HPExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
	HExpireAt(ctx context.Context, key string, tm time.Time, fields ...string) *IntSliceCmd
	HExpireAtWithArgs(ctx context.Context, key string, tm time.Time, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
	HPExpireAt(ctx context.Context, key string, tm time.Time, fields ...string) *IntSliceCmd
	HPExpireAtWithArgs(ctx context.Context, key string, tm time.Time, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
	HPersist(ctx context.Context, key string, fields ...string) *IntSliceCmd
	HExpireTime(ctx context.Context, key string, fields ...string) *IntSliceCmd
	HPExpireTime(ctx context.Context, key string, fields ...string) *IntSliceCmd
	HTTL(ctx context.Context, key string, fields ...string) *IntSliceCmd
	HPTTL(ctx context.Context, key string, fields ...string) *IntSliceCmd
	// note: the HIMPORT API is experimental and may be subject to change.
	HImportPrepare(ctx context.Context, fieldsetName string, fields ...string) *StatusCmd
	HImportSet(ctx context.Context, key, fieldsetName string, values ...interface{}) *StatusCmd
	HImportDiscard(ctx context.Context, fieldsetName string) *IntCmd
	HImportDiscardAll(ctx context.Context) *IntCmd
}

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

func ( cmdable) ( context.Context, ,  string) *BoolCmd {
	 := NewBoolCmd(, "hexists", , )
	_ = (, )
	return 
}

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

// HGetAll returns a map of all fields and values stored at key.
//
// Returns an empty map when key does not exist.
//
// Time complexity: O(N) where N is the size of the hash.
//
// See https://redis.io/commands/hgetall/
func ( cmdable) ( context.Context,  string) *MapStringStringCmd {
	 := NewMapStringStringCmd(, "hgetall", )
	_ = (, )
	return 
}

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

func ( cmdable) ( context.Context, ,  string,  float64) *FloatCmd {
	 := NewFloatCmd(, "hincrbyfloat", , , )
	_ = (, )
	return 
}

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

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

// HMGet returns the values for the specified fields in the hash stored at key.
// It returns an interface{} to distinguish between empty string and nil value.
func ( cmdable) ( context.Context,  string,  ...string) *SliceCmd {
	 := make([]interface{}, 2+len())
	[0] = "hmget"
	[1] = 
	for ,  := range  {
		[2+] = 
	}
	 := NewSliceCmd(, ...)
	_ = (, )
	return 
}

// HSet accepts values in following formats:
//
//   - HSet(ctx, "myhash", "key1", "value1", "key2", "value2")
//
//   - HSet(ctx, "myhash", []string{"key1", "value1", "key2", "value2"})
//
//   - HSet(ctx, "myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})
//
//     Playing struct With "redis" tag.
//     type MyHash struct { Key1 string `redis:"key1"`; Key2 int `redis:"key2"` }
//
//   - HSet(ctx, "myhash", MyHash{"value1", "value2"}) Warn: redis-server >= 4.0
//
//     For struct, can be a structure pointer type, we only parse the field whose tag is redis.
//     if you don't want the field to be read, you can use the `redis:"-"` flag to ignore it,
//     or you don't need to set the redis tag.
//     For the type of structure field, we only support simple data types:
//     string, int/uint(8,16,32,64), float(32,64), time.Time(to RFC3339Nano), time.Duration(to Nanoseconds ),
//     if you are other more complex or custom data types, please implement the encoding.BinaryMarshaler interface.
//
// Note that in older versions of Redis server(redis-server < 4.0), HSet only supports a single key-value pair.
// redis-docs: https://redis.io/commands/hset (Starting with Redis version 4.0.0: Accepts multiple field and value arguments.)
// If you are using a Struct type and the number of fields is greater than one,
// you will receive an error similar to "ERR wrong number of arguments", you can use HMSet as a substitute.
func ( cmdable) ( context.Context,  string,  ...interface{}) *IntCmd {
	 := make([]interface{}, 2, 2+len())
	[0] = "hset"
	[1] = 
	 = appendArgs(, )
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// HMSet is a deprecated version of HSet left for compatibility with Redis 3.
func ( cmdable) ( context.Context,  string,  ...interface{}) *BoolCmd {
	 := make([]interface{}, 2, 2+len())
	[0] = "hmset"
	[1] = 
	 = appendArgs(, )
	 := NewBoolCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, ,  string,  interface{}) *BoolCmd {
	 := NewBoolCmd(, "hsetnx", , , )
	_ = (, )
	return 
}

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

// HRandField redis-server version >= 6.2.0.
func ( cmdable) ( context.Context,  string,  int) *StringSliceCmd {
	 := NewStringSliceCmd(, "hrandfield", , )
	_ = (, )
	return 
}

// HRandFieldWithValues redis-server version >= 6.2.0.
func ( cmdable) ( context.Context,  string,  int) *KeyValueSliceCmd {
	 := NewKeyValueSliceCmd(, "hrandfield", , , "withvalues")
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  uint64,  string,  int64) *ScanCmd {
	 := []interface{}{"hscan", , }
	if  != "" {
		 = append(, "match", )
	}
	if  > 0 {
		 = append(, "count", )
	}
	 := NewScanCmd(, , ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, ,  string) *IntCmd {
	 := NewIntCmd(, "hstrlen", , )
	_ = (, )
	return 
}
func ( cmdable) ( context.Context,  string,  uint64,  string,  int64) *ScanCmd {
	 := []interface{}{"hscan", , }
	if  != "" {
		 = append(, "match", )
	}
	if  > 0 {
		 = append(, "count", )
	}
	 = append(, "novalues")
	 := NewScanCmd(, , ...)
	_ = (, )
	return 
}

type HExpireArgs struct {
	NX bool
	XX bool
	GT bool
	LT bool
}

// HExpire - Sets the expiration time for specified fields in a hash in seconds.
// The command constructs an argument list starting with "HEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
// Available since Redis 7.4 CE.
// For more information refer to [HEXPIRE Documentation].
//
// [HEXPIRE Documentation]: https://redis.io/commands/hexpire/
func ( cmdable) ( context.Context,  string,  time.Duration,  ...string) *IntSliceCmd {
	 := []interface{}{"HEXPIRE", , formatSec(, ), "FIELDS", len()}

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HExpireWithArgs - Sets the expiration time for specified fields in a hash in seconds.
// It requires a key, an expiration duration, a struct with boolean flags for conditional expiration settings (NX, XX, GT, LT), and a list of fields.
// The command constructs an argument list starting with "HEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
// Available since Redis 7.4 CE.
// For more information refer to [HEXPIRE Documentation].
//
// [HEXPIRE Documentation]: https://redis.io/commands/hexpire/
func ( cmdable) ( context.Context,  string,  time.Duration,  HExpireArgs,  ...string) *IntSliceCmd {
	 := []interface{}{"HEXPIRE", , formatSec(, )}

	// only if one argument is true, we can add it to the args
	// if more than one argument is true, it will cause an error
	if .NX {
		 = append(, "NX")
	} else if .XX {
		 = append(, "XX")
	} else if .GT {
		 = append(, "GT")
	} else if .LT {
		 = append(, "LT")
	}

	 = append(, "FIELDS", len())

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HPExpire - Sets the expiration time for specified fields in a hash in milliseconds.
// Similar to HExpire, it accepts a key, an expiration duration in milliseconds, a struct with expiration condition flags, and a list of fields.
// The command modifies the standard time.Duration to milliseconds for the Redis command.
// Available since Redis 7.4 CE.
// For more information refer to [HPEXPIRE Documentation].
//
// [HPEXPIRE Documentation]: https://redis.io/commands/hpexpire/
func ( cmdable) ( context.Context,  string,  time.Duration,  ...string) *IntSliceCmd {
	 := []interface{}{"HPEXPIRE", , formatMs(, ), "FIELDS", len()}

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HPExpireWithArgs - Sets the expiration time for specified fields in a hash in milliseconds.
// It requires a key, an expiration duration, a struct with boolean flags for conditional expiration settings (NX, XX, GT, LT), and a list of fields.
// The command constructs an argument list starting with "HPEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
// Available since Redis 7.4 CE.
// For more information refer to [HPEXPIRE Documentation].
//
// [HPEXPIRE Documentation]: https://redis.io/commands/hpexpire/
func ( cmdable) ( context.Context,  string,  time.Duration,  HExpireArgs,  ...string) *IntSliceCmd {
	 := []interface{}{"HPEXPIRE", , formatMs(, )}

	// only if one argument is true, we can add it to the args
	// if more than one argument is true, it will cause an error
	if .NX {
		 = append(, "NX")
	} else if .XX {
		 = append(, "XX")
	} else if .GT {
		 = append(, "GT")
	} else if .LT {
		 = append(, "LT")
	}

	 = append(, "FIELDS", len())

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HExpireAt - Sets the expiration time for specified fields in a hash to a UNIX timestamp in seconds.
// Takes a key, a UNIX timestamp, a struct of conditional flags, and a list of fields.
// The command sets absolute expiration times based on the UNIX timestamp provided.
// Available since Redis 7.4 CE.
// For more information refer to [HExpireAt Documentation].
//
// [HExpireAt Documentation]: https://redis.io/commands/hexpireat/
func ( cmdable) ( context.Context,  string,  time.Time,  ...string) *IntSliceCmd {

	 := []interface{}{"HEXPIREAT", , .Unix(), "FIELDS", len()}

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  time.Time,  HExpireArgs,  ...string) *IntSliceCmd {
	 := []interface{}{"HEXPIREAT", , .Unix()}

	// only if one argument is true, we can add it to the args
	// if more than one argument is true, it will cause an error
	if .NX {
		 = append(, "NX")
	} else if .XX {
		 = append(, "XX")
	} else if .GT {
		 = append(, "GT")
	} else if .LT {
		 = append(, "LT")
	}

	 = append(, "FIELDS", len())

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HPExpireAt - Sets the expiration time for specified fields in a hash to a UNIX timestamp in milliseconds.
// Similar to HExpireAt but for timestamps in milliseconds. It accepts the same parameters and adjusts the UNIX time to milliseconds.
// Available since Redis 7.4 CE.
// For more information refer to [HExpireAt Documentation].
//
// [HExpireAt Documentation]: https://redis.io/commands/hexpireat/
func ( cmdable) ( context.Context,  string,  time.Time,  ...string) *IntSliceCmd {
	 := []interface{}{"HPEXPIREAT", , .UnixMilli(), "FIELDS", len()}

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  time.Time,  HExpireArgs,  ...string) *IntSliceCmd {
	 := []interface{}{"HPEXPIREAT", , .UnixMilli()}

	// only if one argument is true, we can add it to the args
	// if more than one argument is true, it will cause an error
	if .NX {
		 = append(, "NX")
	} else if .XX {
		 = append(, "XX")
	} else if .GT {
		 = append(, "GT")
	} else if .LT {
		 = append(, "LT")
	}

	 = append(, "FIELDS", len())

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HPersist - Removes the expiration time from specified fields in a hash.
// Accepts a key and the fields themselves.
// This command ensures that each field specified will have its expiration removed if present.
// Available since Redis 7.4 CE.
// For more information refer to [HPersist Documentation].
//
// [HPersist Documentation]: https://redis.io/commands/hpersist/
func ( cmdable) ( context.Context,  string,  ...string) *IntSliceCmd {
	 := []interface{}{"HPERSIST", , "FIELDS", len()}

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HExpireTime - Retrieves the expiration time for specified fields in a hash as a UNIX timestamp in seconds.
// Requires a key and the fields themselves to fetch their expiration timestamps.
// This command returns the expiration times for each field or error/status codes for each field as specified.
// Available since Redis 7.4 CE.
// For more information refer to [HExpireTime Documentation].
//
// [HExpireTime Documentation]: https://redis.io/commands/hexpiretime/
// For more information - https://redis.io/commands/hexpiretime/
func ( cmdable) ( context.Context,  string,  ...string) *IntSliceCmd {
	 := []interface{}{"HEXPIRETIME", , "FIELDS", len()}

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HPExpireTime - Retrieves the expiration time for specified fields in a hash as a UNIX timestamp in milliseconds.
// Similar to HExpireTime, adjusted for timestamps in milliseconds. It requires the same parameters.
// Provides the expiration timestamp for each field in milliseconds.
// Available since Redis 7.4 CE.
// For more information refer to [HExpireTime Documentation].
//
// [HExpireTime Documentation]: https://redis.io/commands/hexpiretime/
// For more information - https://redis.io/commands/hexpiretime/
func ( cmdable) ( context.Context,  string,  ...string) *IntSliceCmd {
	 := []interface{}{"HPEXPIRETIME", , "FIELDS", len()}

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HTTL - Retrieves the remaining time to live for specified fields in a hash in seconds.
// Requires a key and the fields themselves. It returns the TTL for each specified field.
// This command fetches the TTL in seconds for each field or returns error/status codes as appropriate.
// Available since Redis 7.4 CE.
// For more information refer to [HTTL Documentation].
//
// [HTTL Documentation]: https://redis.io/commands/httl/
func ( cmdable) ( context.Context,  string,  ...string) *IntSliceCmd {
	 := []interface{}{"HTTL", , "FIELDS", len()}

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// HPTTL - Retrieves the remaining time to live for specified fields in a hash in milliseconds.
// Similar to HTTL, but returns the TTL in milliseconds. It requires a key and the specified fields.
// This command provides the TTL in milliseconds for each field or returns error/status codes as needed.
// Available since Redis 7.4 CE.
// For more information refer to [HPTTL Documentation].
//
// [HPTTL Documentation]: https://redis.io/commands/hpttl/
// For more information - https://redis.io/commands/hpttl/
func ( cmdable) ( context.Context,  string,  ...string) *IntSliceCmd {
	 := []interface{}{"HPTTL", , "FIELDS", len()}

	for ,  := range  {
		 = append(, )
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  ...string) *StringSliceCmd {
	 := []interface{}{"HGETDEL", , "FIELDS", len()}
	for ,  := range  {
		 = append(, )
	}
	 := NewStringSliceCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  ...string) *StringSliceCmd {
	 := []interface{}{"HGETEX", , "FIELDS", len()}
	for ,  := range  {
		 = append(, )
	}
	 := NewStringSliceCmd(, ...)
	_ = (, )
	return 
}

// HGetEXExpirationType represents an expiration option for the HGETEX command.
type HGetEXExpirationType string

const (
	HGetEXExpirationEX      HGetEXExpirationType = "EX"
	HGetEXExpirationPX      HGetEXExpirationType = "PX"
	HGetEXExpirationEXAT    HGetEXExpirationType = "EXAT"
	HGetEXExpirationPXAT    HGetEXExpirationType = "PXAT"
	HGetEXExpirationPERSIST HGetEXExpirationType = "PERSIST"
)

type HGetEXOptions struct {
	ExpirationType HGetEXExpirationType
	ExpirationVal  int64
}

func ( cmdable) ( context.Context,  string,  *HGetEXOptions,  ...string) *StringSliceCmd {
	 := []interface{}{"HGETEX", }
	if .ExpirationType != "" {
		 = append(, string(.ExpirationType))
		if .ExpirationType != HGetEXExpirationPERSIST {
			 = append(, .ExpirationVal)
		}
	}

	 = append(, "FIELDS", len())
	for ,  := range  {
		 = append(, )
	}

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

type HSetEXCondition string

const (
	HSetEXFNX HSetEXCondition = "FNX" // Only set the fields if none of them already exist.
	HSetEXFXX HSetEXCondition = "FXX" // Only set the fields if all already exist.
)

type HSetEXExpirationType string

const (
	HSetEXExpirationEX      HSetEXExpirationType = "EX"
	HSetEXExpirationPX      HSetEXExpirationType = "PX"
	HSetEXExpirationEXAT    HSetEXExpirationType = "EXAT"
	HSetEXExpirationPXAT    HSetEXExpirationType = "PXAT"
	HSetEXExpirationKEEPTTL HSetEXExpirationType = "KEEPTTL"
)

type HSetEXOptions struct {
	Condition      HSetEXCondition
	ExpirationType HSetEXExpirationType
	ExpirationVal  int64
}

func ( cmdable) ( context.Context,  string,  ...string) *IntCmd {
	 := []interface{}{"HSETEX", , "FIELDS", len() / 2}
	for ,  := range  {
		 = append(, )
	}

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

func ( cmdable) ( context.Context,  string,  *HSetEXOptions,  ...string) *IntCmd {
	 := []interface{}{"HSETEX", }
	if .Condition != "" {
		 = append(, string(.Condition))
	}
	if .ExpirationType != "" {
		 = append(, string(.ExpirationType))
		if .ExpirationType != HSetEXExpirationKEEPTTL {
			 = append(, .ExpirationVal)
		}
	}
	 = append(, "FIELDS", len()/2)
	for ,  := range  {
		 = append(, )
	}

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